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_LIB_INITIALIZE_H_ 17 #define TENSORFLOW_STREAM_EXECUTOR_LIB_INITIALIZE_H_ 18 19 #include "tensorflow/stream_executor/platform/port.h" 20 21 #if defined(PLATFORM_GOOGLE) 22 #include "tensorflow/stream_executor/platform/google/initialize.h" 23 #else 24 25 #undef REGISTER_MODULE_INITIALIZER 26 #undef DECLARE_MODULE_INITIALIZER 27 #undef REGISTER_MODULE_INITIALIZER_SEQUENCE 28 29 namespace perftools { 30 namespace gputools { 31 namespace port { 32 33 class Initializer { 34 public: 35 typedef void (*InitializerFunc)(); 36 explicit Initializer(InitializerFunc func) { func(); } 37 38 struct Dependency { 39 Dependency(const char *n, Initializer *i) : name(n), initializer(i) {} 40 const char *const name; 41 Initializer *const initializer; 42 }; 43 44 struct DependencyRegisterer { 45 DependencyRegisterer(const char *type, const char *name, 46 Initializer *initializer, 47 const Dependency &dependency); 48 }; 49 }; 50 51 } // namespace port 52 } // namespace gputools 53 } // namespace perftools 54 55 #define REGISTER_INITIALIZER(type, name, body) \ 56 static void google_init_##type##_##name() { body; } \ 57 perftools::gputools::port::Initializer google_initializer_##type##_##name( \ 58 google_init_##type##_##name) 59 60 #define REGISTER_MODULE_INITIALIZER(name, body) \ 61 REGISTER_INITIALIZER(module, name, body) 62 63 #define DECLARE_INITIALIZER(type, name) \ 64 extern perftools::gputools::port::Initializer \ 65 google_initializer_##type##_##name 66 67 #define DECLARE_MODULE_INITIALIZER(name) DECLARE_INITIALIZER(module, name) 68 69 #define REGISTER_MODULE_INITIALIZER_SEQUENCE(name1, name2) 70 71 #endif // !defined(PLATFORM_GOOGLE) 72 73 #endif // TENSORFLOW_STREAM_EXECUTOR_LIB_INITIALIZE_H_ 74