xref: /aosp_15_r20/external/pytorch/c10/cuda/README.md (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1c10/cuda is a core library with CUDA functionality.  It is distinguished
2from c10 in that it links against the CUDA library, but like c10 it doesn't
3contain any kernels, and consists solely of core functionality that is generally
4useful when writing CUDA code; for example, C++ wrappers for the CUDA C API.
5
6**Important notes for developers.** If you want to add files or functionality
7to this folder, TAKE NOTE.  The code in this folder is very special,
8because on our AMD GPU build, we transpile it into c10/hip to provide a
9ROCm environment.  Thus, if you write:
10
11```
12// c10/cuda/CUDAFoo.h
13namespace c10 { namespace cuda {
14
15void my_func();
16
17}}
18```
19
20this will get transpiled into:
21
22
23```
24// c10/hip/HIPFoo.h
25namespace c10 { namespace hip {
26
27void my_func();
28
29}}
30```
31
32Thus, if you add new functionality to c10, you must also update `C10_MAPPINGS`
33`torch/utils/hipify/cuda_to_hip_mappings.py` to transpile
34occurrences of `cuda::my_func` to `hip::my_func`.  (At the moment,
35we do NOT have a catch all `cuda::` to `hip::` namespace conversion,
36as not all `cuda` namespaces are converted to `hip::`, even though
37c10's are.)
38
39Transpilation inside this folder is controlled by `CAFFE2_SPECIFIC_MAPPINGS`
40(oddly enough.)  `C10_MAPPINGS` apply to ALL source files.
41
42If you add a new directory to this folder, you MUST update both
43c10/cuda/CMakeLists.txt and c10/hip/CMakeLists.txt
44