• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "absl/strings/string_view.h"
25 #include "tensorflow/core/lib/strings/str_util.h"
26 #include "tensorflow/stream_executor/lib/demangle.h"
27 #include "tensorflow/stream_executor/platform.h"
28 #include "tensorflow/stream_executor/platform/logging.h"
29 #include "tensorflow/stream_executor/stream_executor.h"
30 
31 namespace stream_executor {
32 
registers_per_thread(int * registers_per_thread) const33 bool KernelMetadata::registers_per_thread(int *registers_per_thread) const {
34   if (has_registers_per_thread_) {
35     *registers_per_thread = registers_per_thread_;
36     return true;
37   }
38 
39   return false;
40 }
41 
set_registers_per_thread(int registers_per_thread)42 void KernelMetadata::set_registers_per_thread(int registers_per_thread) {
43   registers_per_thread_ = registers_per_thread;
44   has_registers_per_thread_ = true;
45 }
46 
shared_memory_bytes(int * shared_memory_bytes) const47 bool KernelMetadata::shared_memory_bytes(int *shared_memory_bytes) const {
48   if (has_shared_memory_bytes_) {
49     *shared_memory_bytes = shared_memory_bytes_;
50     return true;
51   }
52 
53   return false;
54 }
55 
set_shared_memory_bytes(int shared_memory_bytes)56 void KernelMetadata::set_shared_memory_bytes(int shared_memory_bytes) {
57   shared_memory_bytes_ = shared_memory_bytes;
58   has_shared_memory_bytes_ = true;
59 }
60 
KernelBase(KernelBase && from)61 KernelBase::KernelBase(KernelBase &&from)
62     : parent_(from.parent_),
63       implementation_(std::move(from.implementation_)),
64       name_(std::move(from.name_)),
65       demangled_name_(std::move(from.demangled_name_)),
66       metadata_(from.metadata_) {
67   from.parent_ = nullptr;
68 }
69 
KernelBase(StreamExecutor * parent)70 KernelBase::KernelBase(StreamExecutor *parent)
71     : parent_(parent),
72       implementation_(parent->implementation()->CreateKernelImplementation()) {}
73 
KernelBase(StreamExecutor * parent,internal::KernelInterface * implementation)74 KernelBase::KernelBase(StreamExecutor *parent,
75                        internal::KernelInterface *implementation)
76     : parent_(parent), implementation_(implementation) {}
77 
~KernelBase()78 KernelBase::~KernelBase() {
79   if (parent_) {
80     parent_->UnloadKernel(this);
81   }
82 }
83 
Arity() const84 unsigned KernelBase::Arity() const { return implementation_->Arity(); }
85 
SetPreferredCacheConfig(KernelCacheConfig config)86 void KernelBase::SetPreferredCacheConfig(KernelCacheConfig config) {
87   return implementation_->SetPreferredCacheConfig(config);
88 }
89 
GetPreferredCacheConfig() const90 KernelCacheConfig KernelBase::GetPreferredCacheConfig() const {
91   return implementation_->GetPreferredCacheConfig();
92 }
93 
94 // Prefix stub functions emitted by the CUDA splitter.
95 static const char *kStubPrefix = "__device_stub_";
96 
set_name(absl::string_view name)97 void KernelBase::set_name(absl::string_view name) {
98   name_ = string(name);
99   absl::string_view stubless_name = name;
100   if (tensorflow::str_util::StartsWith(name, kStubPrefix)) {
101     stubless_name.remove_prefix(strlen(kStubPrefix));
102   }
103   demangled_name_ = port::Demangle(stubless_name.data());
104 }
105 
106 }  // namespace stream_executor
107