1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_CORE_UTIL_GPU_CUDA_ALIAS_H_
17 #define TENSORFLOW_CORE_UTIL_GPU_CUDA_ALIAS_H_
18 
19 // Several forwarding macros are defined in this file to serve for backward
20 // compatibility usage as we migrating from CUDA prefixed function to GPU
21 // prefixed functions. Both Cuda and ROCm can unify under the new GPU prefix
22 // naming scheme. In the migration period, we provide equivalent CUDA* and GPU*
23 // function. Over time, all CUDA* functions will be deprecated.
24 
25 namespace tensorflow {
26 
27 // CREATE_CUDA_HOST_FUNCTION_ALIAS forward the host function to its CUDA Alias.
28 #ifndef TENSORFLOW_USE_ROCM
29 #define CREATE_CUDA_HOST_FUNCTION_ALIAS(func, cuda_alias) \
30   template <typename... Args>                             \
31   auto cuda_alias(Args&&... args)                         \
32       ->decltype(func(std::forward<Args>(args)...)) {     \
33     return func(std::forward<Args>(args)...);             \
34   }
35 #else
36 #define CREATE_CUDA_HOST_FUNCTION_ALIAS(func, cuda_alias)
37 #endif
38 
39 // CREATE_CUDA_DEVICE_FUNCTION_ALIAS forward the device function to its CUDA
40 // Alias.
41 #ifndef TENSORFLOW_USE_ROCM
42 #define CREATE_CUDA_DEVICE_FUNCTION_ALIAS(func, cuda_alias) \
43   template <typename... Args>                               \
44   __device__ auto cuda_alias(Args&&... args)                \
45       ->decltype(func(std::forward<Args>(args)...)) {       \
46     return func(std::forward<Args>(args)...);               \
47   }
48 #else
49 #define CREATE_CUDA_DEVICE_FUNCTION_ALIAS(func, cuda_alias)
50 #endif
51 
52 // CREATE_CUDA_TYPE_ALIAS forward the type to its CUDA Alias.
53 #ifndef TENSORFLOW_USE_ROCM
54 #define CREATE_CUDA_TYPE_ALIAS(type, cuda_alias) using cuda_alias = type;
55 #else
56 #define CREATE_CUDA_TYPE_ALIAS(type, cuda_alias)
57 #endif
58 }  // namespace tensorflow
59 
60 #endif  // TENSORFLOW_CORE_UTIL_GPU_CUDA_ALIAS_H_
61