TensorGpuHipCudaDefines.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
5 // Copyright (C) 2018 Deven Desai <deven.desai.amd@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #if defined(EIGEN_USE_GPU) && !defined(EIGEN_CXX11_TENSOR_GPU_HIP_CUDA_DEFINES_H)
12 #define EIGEN_CXX11_TENSOR_GPU_HIP_CUDA_DEFINES_H
13 
14 // Note that we are using EIGEN_USE_HIP here instead of EIGEN_HIPCC...this is by design
15 // There is code in the Tensorflow codebase that will define EIGEN_USE_GPU, but
16 // for some reason gets sent to the gcc/host compiler instead of the gpu/nvcc/hipcc compiler
17 // When compiling such files, gcc will end up trying to pick up the CUDA headers by
18 // default (see the code within "unsupported/Eigen/CXX11/Tensor" that is guarded by EIGEN_USE_GPU)
19 // This will obviously not work when trying to compile tensorflow on a system with no CUDA
20 // To work around this issue for HIP systems (and leave the default behaviour intact), the
21 // HIP tensorflow build defines EIGEN_USE_HIP when compiling all source files, and
22 // "unsupported/Eigen/CXX11/Tensor" has been updated to use HIP header when EIGEN_USE_HIP is
23 // defined. In continuation of that requirement, the guard here needs to be EIGEN_USE_HIP as well
24 
25 #if defined(EIGEN_USE_HIP)
26 
27 #define gpuStream_t hipStream_t
28 #define gpuDeviceProp_t hipDeviceProp_t
29 #define gpuError_t hipError_t
30 #define gpuSuccess hipSuccess
31 #define gpuErrorNotReady hipErrorNotReady
32 #define gpuGetDeviceCount hipGetDeviceCount
33 #define gpuGetLastError hipGetLastError
34 #define gpuPeekAtLastError hipPeekAtLastError
35 #define gpuGetErrorName hipGetErrorName
36 #define gpuGetErrorString hipGetErrorString
37 #define gpuGetDeviceProperties hipGetDeviceProperties
38 #define gpuStreamDefault hipStreamDefault
39 #define gpuGetDevice hipGetDevice
40 #define gpuSetDevice hipSetDevice
41 #define gpuMalloc hipMalloc
42 #define gpuFree hipFree
43 #define gpuMemsetAsync hipMemsetAsync
44 #define gpuMemset2DAsync hipMemset2DAsync
45 #define gpuMemcpyAsync hipMemcpyAsync
46 #define gpuMemcpyDeviceToDevice hipMemcpyDeviceToDevice
47 #define gpuMemcpyDeviceToHost hipMemcpyDeviceToHost
48 #define gpuMemcpyHostToDevice hipMemcpyHostToDevice
49 #define gpuStreamQuery hipStreamQuery
50 #define gpuSharedMemConfig hipSharedMemConfig
51 #define gpuDeviceSetSharedMemConfig hipDeviceSetSharedMemConfig
52 #define gpuStreamSynchronize hipStreamSynchronize
53 #define gpuDeviceSynchronize hipDeviceSynchronize
54 #define gpuMemcpy hipMemcpy
55 
56 #else
57 
58 #define gpuStream_t cudaStream_t
59 #define gpuDeviceProp_t cudaDeviceProp
60 #define gpuError_t cudaError_t
61 #define gpuSuccess cudaSuccess
62 #define gpuErrorNotReady cudaErrorNotReady
63 #define gpuGetDeviceCount cudaGetDeviceCount
64 #define gpuGetLastError cudaGetLastError
65 #define gpuPeekAtLastError cudaPeekAtLastError
66 #define gpuGetErrorName cudaGetErrorName
67 #define gpuGetErrorString cudaGetErrorString
68 #define gpuGetDeviceProperties cudaGetDeviceProperties
69 #define gpuStreamDefault cudaStreamDefault
70 #define gpuGetDevice cudaGetDevice
71 #define gpuSetDevice cudaSetDevice
72 #define gpuMalloc cudaMalloc
73 #define gpuFree cudaFree
74 #define gpuMemsetAsync cudaMemsetAsync
75 #define gpuMemset2DAsync cudaMemset2DAsync
76 #define gpuMemcpyAsync cudaMemcpyAsync
77 #define gpuMemcpyDeviceToDevice cudaMemcpyDeviceToDevice
78 #define gpuMemcpyDeviceToHost cudaMemcpyDeviceToHost
79 #define gpuMemcpyHostToDevice cudaMemcpyHostToDevice
80 #define gpuStreamQuery cudaStreamQuery
81 #define gpuSharedMemConfig cudaSharedMemConfig
82 #define gpuDeviceSetSharedMemConfig cudaDeviceSetSharedMemConfig
83 #define gpuStreamSynchronize cudaStreamSynchronize
84 #define gpuDeviceSynchronize cudaDeviceSynchronize
85 #define gpuMemcpy cudaMemcpy
86 
87 #endif
88 
89 // gpu_assert can be overridden
90 #ifndef gpu_assert
91 
92 #if defined(EIGEN_HIP_DEVICE_COMPILE)
93 // HIPCC do not support the use of assert on the GPU side.
94 #define gpu_assert(COND)
95 #else
96 #define gpu_assert(COND) eigen_assert(COND)
97 #endif
98 
99 #endif // gpu_assert
100 
101 #endif // EIGEN_CXX11_TENSOR_GPU_HIP_CUDA_DEFINES_H