1 /* Copyright 2016 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_CORE_FRAMEWORK_SELECTIVE_REGISTRATION_H_ 17 #define TENSORFLOW_CORE_FRAMEWORK_SELECTIVE_REGISTRATION_H_ 18 19 #include <string.h> 20 21 #ifdef SELECTIVE_REGISTRATION 22 23 // Experimental selective registration support to reduce binary size. 24 // 25 // To use selective registration, when building: 26 // 1. define SELECTIVE_REGISTRATION, e.g. in gcc by passing 27 // -DSELECTIVE_REGISTRATION to compilation. 28 // 2. Provide ops_to_register.h. This file is not included in the repo and must 29 // be placed by the user or a tool where the compiler can find it. It must 30 // define the constants and functions used in the macros below. The 31 // functions should be defined as valid constexpr functions, so that they are 32 // evaluated at compile time: this is needed to make symbols referenced by 33 // un-registered objects unused, and therefore allow the linker to strip them 34 // out. See python/tools/print_selective_registration_header.py for a tool 35 // that can be used to generate ops_to_register.h. 36 // 37 // ops_to_register.h should define macros for: 38 // // Ops for which this is false will not be registered. 39 // SHOULD_REGISTER_OP(op) 40 // // If this is false, then no gradient ops are registered. 41 // SHOULD_REGISTER_OP_GRADIENT 42 // // Op kernel classes where this is false won't be registered. 43 // SHOULD_REGISTER_OP_KERNEL(clz) 44 // The macros should be defined using constexprs. 45 46 #include "ops_to_register.h" 47 48 #if (!defined(SHOULD_REGISTER_OP) || !defined(SHOULD_REGISTER_OP_GRADIENT) || \ 49 !defined(SHOULD_REGISTER_OP_KERNEL)) 50 static_assert(false, "ops_to_register.h must define SHOULD_REGISTER macros"); 51 #endif 52 #else 53 #define SHOULD_REGISTER_OP(op) true 54 #define SHOULD_REGISTER_OP_GRADIENT true 55 #define SHOULD_REGISTER_OP_KERNEL(clz) true 56 #endif 57 58 #endif // TENSORFLOW_CORE_FRAMEWORK_SELECTIVE_REGISTRATION_H_ 59