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_PLATFORM_DEFAULT_INITIALIZE_H_
17 #define TENSORFLOW_STREAM_EXECUTOR_PLATFORM_DEFAULT_INITIALIZE_H_
18 
19 #undef REGISTER_MODULE_INITIALIZER
20 #undef DECLARE_MODULE_INITIALIZER
21 #undef REGISTER_MODULE_INITIALIZER_SEQUENCE
22 
23 namespace stream_executor {
24 namespace port {
25 
26 class Initializer {
27  public:
28   typedef void (*InitializerFunc)();
Initializer(InitializerFunc func)29   explicit Initializer(InitializerFunc func) { func(); }
30 
31   struct Dependency {
DependencyDependency32     Dependency(const char *n, Initializer *i) : name(n), initializer(i) {}
33     const char *const name;
34     Initializer *const initializer;
35   };
36 
37   struct DependencyRegisterer {
38     DependencyRegisterer(const char *type, const char *name,
39                          Initializer *initializer,
40                          const Dependency &dependency);
41   };
42 };
43 
44 }  // namespace port
45 }  // namespace stream_executor
46 
47 #define REGISTER_INITIALIZER(type, name, body)                             \
48   static void google_init_##type##_##name() { body; }                      \
49   ::stream_executor::port::Initializer google_initializer_##type##_##name( \
50       google_init_##type##_##name)
51 
52 #define REGISTER_MODULE_INITIALIZER(name, body) \
53   REGISTER_INITIALIZER(module, name, body)
54 
55 #define DECLARE_INITIALIZER(type, name) \
56   extern ::stream_executor::port::Initializer google_initializer_##type##_##name
57 
58 #define DECLARE_MODULE_INITIALIZER(name) DECLARE_INITIALIZER(module, name)
59 
60 #define REGISTER_MODULE_INITIALIZER_SEQUENCE(name1, name2)
61 
62 #endif  // TENSORFLOW_STREAM_EXECUTOR_PLATFORM_DEFAULT_INITIALIZE_H_
63