Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.
时间: 2023-11-01 13:59:19 浏览: 117
This is a compile-time flag for PyTorch that enables device-side assertions (DSA) when running CUDA code. Device-side assertions are a debugging tool that allows developers to check for errors that occur on the GPU during runtime.
To compile PyTorch with `TORCH_USE_CUDA_DSA` flag, you need to rebuild PyTorch from source. Here are the steps to do that:
1. Clone the PyTorch repository from GitHub:
```
git clone --recursive https://github.com/pytorch/pytorch
```
2. Checkout the branch or tag you want to build:
```
cd pytorch
git checkout <branch or tag>
```
3. Install the dependencies needed to build PyTorch. You can find the list of dependencies in the PyTorch documentation.
4. Set the environment variables needed to build PyTorch:
```
export CMAKE_PREFIX_PATH=/path/to/libtorch
export CUDA_HOME=/usr/local/cuda
```
`CMAKE_PREFIX_PATH` should point to the location where you installed the C++ API for PyTorch. `CUDA_HOME` should point to the location where CUDA is installed on your system.
5. Build PyTorch with the `TORCH_USE_CUDA_DSA` flag:
```
python setup.py build --cmake --define TORCH_USE_CUDA_DSA=ON
```
This will build PyTorch with device-side assertions enabled. Once the build is complete, you can install PyTorch by running:
```
python setup.py install
```
Note that enabling device-side assertions can significantly slow down your code, so it is recommended to only use them for debugging purposes.
阅读全文