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 #ifndef TENSORFLOW_STREAM_EXECUTOR_PLUGIN_H_ 17 #define TENSORFLOW_STREAM_EXECUTOR_PLUGIN_H_ 18 19 namespace stream_executor { 20 21 // A plugin ID is a unique identifier for each registered plugin type. 22 typedef void* PluginId; 23 24 // Helper macro to define a plugin ID. To be used only inside plugin 25 // implementation files. Works by "reserving" an address/value (guaranteed to be 26 // unique) inside a process space. 27 #define PLUGIN_REGISTRY_DEFINE_PLUGIN_ID(ID_VAR_NAME) \ 28 namespace { \ 29 int plugin_id_value; \ 30 } \ 31 const PluginId ID_VAR_NAME = &plugin_id_value; 32 33 // kNullPlugin denotes an invalid plugin identifier. 34 extern const PluginId kNullPlugin; 35 36 // Enumeration to list the supported types of plugins / support libraries. 37 enum class PluginKind { 38 kInvalid, 39 kBlas, 40 kDnn, 41 kFft, 42 kRng, 43 }; 44 45 // A PluginConfig describes the set of plugins to be used by a StreamExecutor 46 // instance. Each plugin is defined by an arbitrary identifier, usually best set 47 // to the address static member in the implementation (to avoid conflicts). 48 // 49 // A PluginConfig may be passed to the StreamExecutor constructor - the plugins 50 // described therein will be used to provide BLAS, DNN, FFT, and RNG 51 // functionality. Platform-appropriate defaults will be used for any un-set 52 // libraries. If a platform does not support a specified plugin (ex. cuBLAS on 53 // an OpenCL executor), then an error will be logged and no plugin operations 54 // will succeed. 55 // 56 // The StreamExecutor BUILD target does not link ANY plugin libraries - even 57 // common host fallbacks! Any plugins must be explicitly linked by dependent 58 // targets. See the cuda, opencl and host BUILD files for implemented plugin 59 // support (search for "plugin"). 60 class PluginConfig { 61 public: 62 // Value specifying the platform's default option for that plugin. 63 static const PluginId kDefault; 64 65 // Initializes all members to the default options. 66 PluginConfig(); 67 68 bool operator==(const PluginConfig& rhs) const; 69 70 // Sets the appropriate library kind to that passed in. 71 PluginConfig& SetBlas(PluginId blas); 72 PluginConfig& SetDnn(PluginId dnn); 73 PluginConfig& SetFft(PluginId fft); 74 PluginConfig& SetRng(PluginId rng); 75 76 PluginId blas() const { return blas_; } 77 PluginId dnn() const { return dnn_; } 78 PluginId fft() const { return fft_; } 79 PluginId rng() const { return rng_; } 80 81 private: 82 PluginId blas_, dnn_, fft_, rng_; 83 }; 84 85 } // namespace stream_executor 86 87 #endif // TENSORFLOW_STREAM_EXECUTOR_PLUGIN_H_ 88