Search code examples
cudagpusublimetext3nvcc

Run a cuda file using terminal / IDE


I have a test.cu cuda file which I want to run and compile. Following are the things that I tried.

  1. Build a cuda build system in sublime-text 4
{
    "shell_cmd": "nvcc $file_name -o ${file_base_name} && ${file_path}/${file_base_name}",
    "working_dir": "$file_path",
    "selector": "source.cu, source.lib, source.exp",
    "path": "/usr/lib/nvidia-cuda-toolkit/bin",
    "shell": true
}

However, after compiling test.cu with the above system. I got

/usr/bin/env: ‘bash’: No such file or directory
[Finished in 6ms with exit code 127]
[shell_cmd: nvcc test.cu -o test && /home/name/My Data/Code Repo/Geometric Learning/test]
[dir: /home/name/My Data/Code Repo/Geometric Learning]
[path: /home/name/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]
  1. compile using terminal
nvcc test.cu -o test

which generates a.out and test. after this I ran

test

Which returned nothing.

How can I compile and run the code (preferably in sublime text)?

System Specifications: nvcc 10.1 + ubuntu 20.04 os.


Solution

  • Following are the ways by which one can compile .cu file

    1. terminal
    $ nvcc test.cu 
    $ ./a.out
    
    1. sublime build system
    {
        "shell_cmd": "nvcc \"${file_path}/${file_name}\" && ./a.out && rm a.out",
        "working_dir": "$file_path",
        "selector": "source.cu, source.lib, source.exp",
        "shell": true
    }