1 /* Copyright 2016 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 // Contains structs and functions to be included in device code. 17 18 #ifndef TENSORFLOW_CORE_KERNELS_CUDA_DEVICE_ARRAY_GPU_H_ 19 #define TENSORFLOW_CORE_KERNELS_CUDA_DEVICE_ARRAY_GPU_H_ 20 21 #if GOOGLE_CUDA || TENSORFLOW_USE_ROCM 22 23 namespace tensorflow { 24 25 static constexpr int kMaxInlineGpuPointers = 8; 26 // To decode on the device side, use GetGpuDeviceArrayOnDevice. 27 // To encode on the host side, use GpuDeviceArrayOnHost. 28 template <typename ValueType, int MaxInlineValues = 8> 29 struct GpuDeviceArrayStruct { 30 int32 size; 31 // used if size <= MaxInlineValues; 32 ValueType inline_values[MaxInlineValues]; 33 ValueType* out_of_line_values = nullptr; // used if size > MaxInlineValues; 34 }; 35 36 template <typename ValueType, int MaxInlineValues = 8> 37 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ValueType* GetGpuDeviceArrayOnDevice( 38 GpuDeviceArrayStruct<ValueType, MaxInlineValues>* data) { 39 if (data->size <= MaxInlineValues) { 40 return data->inline_values; 41 } else { 42 return data->out_of_line_values; 43 } 44 } 45 46 } // namespace tensorflow 47 48 #endif // GOOGLE_CUDA || TENSORFLOW_USE_ROCM 49 50 #endif // TENSORFLOW_CORE_KERNELS_CUDA_DEVICE_ARRAY_GPU_H_ 51