1 /* Copyright 2015 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 // Implementation of the pointer-to-implementation wrapper for the data-parallel 17 // kernel abstraction. KernelBase just delegates to the internal 18 // platform-specific implementation instance. 19 20 #include "tensorflow/stream_executor/kernel.h" 21 22 #include "tensorflow/stream_executor/platform/port.h" 23 24 #include "tensorflow/stream_executor/lib/demangle.h" 25 #include "tensorflow/stream_executor/platform.h" 26 #include "tensorflow/stream_executor/platform/logging.h" 27 #include "tensorflow/stream_executor/stream_executor.h" 28 29 namespace perftools { 30 namespace gputools { 31 32 bool KernelMetadata::registers_per_thread(int *registers_per_thread) const { 33 if (has_registers_per_thread_) { 34 *registers_per_thread = registers_per_thread_; 35 return true; 36 } 37 38 return false; 39 } 40 41 void KernelMetadata::set_registers_per_thread(int registers_per_thread) { 42 registers_per_thread_ = registers_per_thread; 43 has_registers_per_thread_ = true; 44 } 45 46 bool KernelMetadata::shared_memory_bytes(int *shared_memory_bytes) const { 47 if (has_shared_memory_bytes_) { 48 *shared_memory_bytes = shared_memory_bytes_; 49 return true; 50 } 51 52 return false; 53 } 54 55 void KernelMetadata::set_shared_memory_bytes(int shared_memory_bytes) { 56 shared_memory_bytes_ = shared_memory_bytes; 57 has_shared_memory_bytes_ = true; 58 } 59 60 KernelBase::KernelBase(KernelBase &&from) 61 : parent_(from.parent_), 62 implementation_(std::move(from.implementation_)), 63 name_(std::move(from.name_)), 64 demangled_name_(std::move(from.demangled_name_)), 65 metadata_(from.metadata_) { 66 from.parent_ = nullptr; 67 } 68 69 KernelBase::KernelBase(StreamExecutor *parent) 70 : parent_(parent), 71 implementation_(parent->implementation()->CreateKernelImplementation()) {} 72 73 KernelBase::KernelBase(StreamExecutor *parent, 74 internal::KernelInterface *implementation) 75 : parent_(parent), implementation_(implementation) {} 76 77 KernelBase::~KernelBase() { 78 if (parent_) { 79 parent_->UnloadKernel(this); 80 } 81 } 82 83 unsigned KernelBase::Arity() const { return implementation_->Arity(); } 84 85 void KernelBase::SetPreferredCacheConfig(KernelCacheConfig config) { 86 return implementation_->SetPreferredCacheConfig(config); 87 } 88 89 KernelCacheConfig KernelBase::GetPreferredCacheConfig() const { 90 return implementation_->GetPreferredCacheConfig(); 91 } 92 93 // Prefix stub functions emitted by the CUDA splitter. 94 static const char *kStubPrefix = "__device_stub_"; 95 96 void KernelBase::set_name(port::StringPiece name) { 97 name_ = name.ToString(); 98 port::StringPiece stubless_name = name; 99 if (name.starts_with(kStubPrefix)) { 100 stubless_name.remove_prefix(strlen(kStubPrefix)); 101 } 102 demangled_name_ = port::Demangle(stubless_name.data()); 103 } 104 105 } // namespace gputools 106 } // namespace perftools 107