This extension aims at providing syntax support and snippets for CUDA (C++) in VS Code.
This extension DOES NOT provide "IntelliSense like" features, as the task to implement it is really big. Use this extension when you quickly need to edit a kernel or a __device__ function and want the variables and functions to be readable.
This extension supports most of the basic CUDA keywords and functions, such as but not limited to :
- cudaMalloc, cudaFree, ...
- __global__, __device__, __host__, ...
- atomicAdd, atomicSub, surfCubemapLayeredread, ...
- __shfl_down, __syncthreads, ...
To maximize compatibility with existing popular themes, textmate language grammar guidelines have not always been respected (external libraries like CUDA in support scope). If your theme still doesn't color the CUDA code, you can set them with the template rules below (put this into your VSCode user settings in settings.json). This can also be used to override your theme colors, if you want to separate C++ and CUDA colors.
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "support.function.cuda-cpp",
"settings":{
"foreground": "#56b6c2"
}
},
{
"scope": "keyword.function.qualifier.cuda-cpp",
"settings":{
"foreground": "#56b6c2"
}
}
]
}
- "support.function.cuda-cpp" : atomicAdd, cudaMalloc, cudaFree, ...
- "keyword.function.qualifier.cuda-cpp" : __global__, __host__, __device__, ...
- "storage.modifier.cuda-cpp" : __constant__, __device__, __shared__, ...
- "support.type.cuda-cpp" : dim3, uint1, ulong1, ...
- "variable.language.cuda-cpp" : gridDim, blockIdx, blockDim, threadIdx, warpSize
- "punctuation.section.kernel" : the kernel brackets <<< >>>
- "meta.kernel-call.cuda-cpp entity.name.function.c" : the function name before the <<< >>>
The following snippets are available :
- __s : __syncthreads();
- cmal : cudaMalloc((void**)&${1:variable}, ${2:bytes});
- cmalmng : cudaMallocManaged((void**)&${1:variable}, ${2:bytes});
- cmem : cudaMemcpy(${1:dest}, ${2:src}, ${3:bytes}, cudaMemcpy${4:Host}To${5:Device});
- cfree : cudaFree(${1:variable});
- kerneldef : __global__ void ${1:kernel}(${2}) {\n}
- kernelcall : ${1:kernel}<<<${2},${3}>>>(${4});
- thrusthv : thrust::host_vector<${1:char}> v$0;
- thrustdv : thrust::device_vector<${1:char}> v$0;
- VSCode 1.18+. Slightly older versions should work, very old versions are not guaranteed to work.
- This extension has been tested with the default VSCode skin (dark+) and the popular One Dark Pro theme.
This extension contributes the following settings:
- none
- No support for Intellisense navigation through code (right click->Go to definition,...). This will be implemented by another extension dedicated to IntelliSense and debugging. For now, the development is on hold indefinitely. Anyone is welcome to overtake or fork it.
Below are listed the features that ideally should be available for this extension. IntelliSense and debugging coexist in another repository. There is no guarantees this features will be implemented.
- Icon for files
- CUDA syntax colors as parameters of this extension instead of using "editor.tokenColorCustomizations" in settings.json
Requests should be made here : https://github.com/kriegalex/vscode-cuda/issues
See also the changelog
Initial release of vscode-cuda extension
Better documentation