1 /* Copyright 2018 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_STREAM_EXECUTOR_MODULE_SPEC_H_ 17 #define TENSORFLOW_STREAM_EXECUTOR_MODULE_SPEC_H_ 18 19 #include "tensorflow/stream_executor/lib/array_slice.h" 20 #include "tensorflow/stream_executor/platform/logging.h" 21 #include "tensorflow/stream_executor/platform/port.h" 22 23 namespace stream_executor { 24 25 // Describes how to load a module on a target platform. 26 // 27 // The exact meaning of a "module" may differ from platform to platform but 28 // loosely speaking a module a collection of kernels and global variables. It 29 // corresponds to CUmodule when running on CUDA. 30 class MultiModuleLoaderSpec { 31 public: has_cuda_cubin_in_memory()32 bool has_cuda_cubin_in_memory() const { return has_cuda_cubin_in_memory_; } cuda_cubin_in_memory()33 port::ArraySlice<const uint8> cuda_cubin_in_memory() const { 34 CHECK(has_cuda_cubin_in_memory()); 35 return {cuda_cubin_in_memory_.data(), cuda_cubin_in_memory_.size()}; 36 } 37 has_cuda_ptx_in_memory()38 bool has_cuda_ptx_in_memory() const { return has_cuda_ptx_in_memory_; } cuda_ptx_in_memory()39 const char* cuda_ptx_in_memory() const { 40 CHECK(has_cuda_ptx_in_memory()); 41 return cuda_ptx_in_memory_; 42 } 43 AddCudaCubinInMemory(port::ArraySlice<const uint8> cubin_bytes)44 void AddCudaCubinInMemory(port::ArraySlice<const uint8> cubin_bytes) { 45 CHECK(!cubin_bytes.empty()); 46 has_cuda_cubin_in_memory_ = true; 47 cuda_cubin_in_memory_ = cubin_bytes; 48 } 49 AddCudaPtxInMemory(const char * ptx)50 void AddCudaPtxInMemory(const char* ptx) { 51 has_cuda_ptx_in_memory_ = true; 52 // The CUDA driver does not like getting an empty string as PTX. 53 cuda_ptx_in_memory_ = *ptx ? ptx : nullptr; 54 } 55 56 private: 57 port::ArraySlice<const uint8> cuda_cubin_in_memory_; 58 bool has_cuda_cubin_in_memory_ = false; 59 const char* cuda_ptx_in_memory_; 60 bool has_cuda_ptx_in_memory_ = false; 61 }; 62 63 } // namespace stream_executor 64 65 #endif // TENSORFLOW_STREAM_EXECUTOR_MODULE_SPEC_H_ 66