https://github.com/pjueon/cuda_intellisense
A simple python script to fix cuda C++ intellisense for visual studio.
https://github.com/pjueon/cuda_intellisense
cuda visual-studio
Last synced: 3 months ago
JSON representation
A simple python script to fix cuda C++ intellisense for visual studio.
- Host: GitHub
- URL: https://github.com/pjueon/cuda_intellisense
- Owner: pjueon
- License: mit
- Created: 2022-05-23T13:27:38.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-19T04:13:29.000Z (about 4 years ago)
- Last Synced: 2024-10-24T04:29:14.223Z (over 1 year ago)
- Topics: cuda, visual-studio
- Language: Python
- Homepage:
- Size: 314 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cuda_intellisense
A simple python script to fix cuda C++ IntelliSense for visual studio.
**Note**
With the latest version of the Visual Studio, maybe you don't need cuda_intellisense any more.
## Background
If you write cuda C++ code with Visual Studio, you might see some annoying red lines like this:

Typicially you can find theses red lines on:
- texture reference, surface reference (when you didn't define macro `__CUDACC__`)
- kernel arguments (`<<< ... >>>`)
- cuda macros like `__global__`, `__host__` (when you explicitly defined macro `__CUDACC__`)
With cuda_intellisense, you can fix this!

## Installation
First, clone this repository.
```shell
git clone https://github.com/pjueon/cuda_intellisense.git
cd cuda_intellisense
```
And then, run the `scripts/cuda_intellisense.py` file.
**Note**
You should run it as administrator.
```shell
python scripts/cuda_intellisense.py [options]
```
### Install options
|Option|Description|
|------|-----------|
|`--path=`, `-p`|installation path. default value: `${CUDA_PATH}/include`|
|`--cuda_path=`|name of the cuda path environment variable (ex> `CUDA_PATH_v10_2`). default value: `CUDA_PATH`|
|`--version`|show the version of cuda_intellisense.|
|`--uninstall`|uninstall cuda_intellisense.|
|`--help`, `-h`|show help.|
That's it!
## Usage
After installation, the Visual Studio will stop complaining about cuda code except for the kernel arguments(`<<< ... >>>`).
For the kernel arguments, you can use `KERNEL_ARGS` macro.
It works just like `<<< ... >>>`:
- `KERNEL_ARGS(grid, block)` is equal to `<<>>`
- `KERNEL_ARGS(grid, block, sh_mem)` is equal to `<<>>`
- `KERNEL_ARGS(grid, block, sh_mem, stream)` is equal to `<<>>`
**Note**
**You should add `cuda_intellisense/kernel_args.h` file to your source tree** unless those who didn't install the cuda_intellisense won't be able to build your code.
Create `cuda_intellisense` directory to your project and copy `kernel_args.h` file from `headers` directory of this repository or your installation path.
```cpp
# include "cuda_intellisense/kernel_args.h" // for KERNEL_ARGS macro
/* ... */
// equal to addKernel <<>> (dev_c, dev_b, dev_a);
addKernel KERNEL_ARGS(grid, block) (dev_c, dev_b, dev_a);
```
## How does it work?
The trick is using the [`__INTELLISENSE__`](https://devblogs.microsoft.com/cppblog/troubleshooting-tips-for-intellisense-slowness/) macro, which is only defined when using the IntelliSense compiler. cuda_intellisense uses `#ifdef __INTELLISENSE__` macro to hide stuff from the IntelliSense compiler.
So the IntelliSense compiler cannot see the cuda codes that it cannot understand and stop complaining about them.
## Test environment
cuda_intellisense was tested on the following environment.
- OS: Windows 10
- Visual Studio version: 2019, 2022
- CUDA Toolkit version: 10.2, 11.1