1 // Generated by tfcompile, the TensorFlow graph compiler. DO NOT EDIT! 2 // 3 // This header was generated via ahead-of-time compilation of a TensorFlow 4 // graph. An object file corresponding to this header was also generated. 5 // This header gives access to the functionality in that object file. 6 // 7 // clang-format off 8 9 #ifndef TFCOMPILE_GENERATED_entry_point_H_ // NOLINT(build/header_guard) 10 #define TFCOMPILE_GENERATED_entry_point_H_ // NOLINT(build/header_guard) 11 12 #include "tensorflow/compiler/xla/xla_data.pb.h" 13 #include "tensorflow/compiler/tf2xla/xla_compiled_cpu_function.h" 14 #include "tensorflow/core/platform/types.h" 15 16 namespace Eigen { struct ThreadPoolDevice; } 17 namespace xla { class ExecutableRunOptions; } 18 19 // (Implementation detail) Entry point to the function in the object file. 20 extern "C" void entry_point( 21 void* result, const xla::ExecutableRunOptions* run_options, 22 const void** args, void** temps, tensorflow::int64* profile_counters); 23 24 extern "C" char __tfcompile_foo_bar_MyClass_ProgramShape_protobuf_array_contents[]; 25 26 namespace foo { 27 namespace bar { 28 29 // MyClass represents a computation previously specified in a 30 // TensorFlow graph, now compiled into executable code. This extends the generic 31 // XlaCompiledCpuFunction class with statically type-safe arg and result 32 // methods. Usage example: 33 // 34 // MyClass computation; 35 // // ...set args using computation.argN methods 36 // CHECK(computation.Run()); 37 // // ...inspect results using computation.resultN methods 38 // 39 // The Run method invokes the actual computation, with inputs read from arg 40 // buffers, and outputs written to result buffers. Each Run call may also use 41 // a set of temporary buffers for the computation. 42 // 43 // By default each instance of this class manages its own arg, result and temp 44 // buffers. The AllocMode constructor parameter may be used to modify the 45 // buffer allocation strategy. 46 // 47 // Under the default allocation strategy, this class is thread-compatible: 48 // o Calls to non-const methods require exclusive access to the object. 49 // o Concurrent calls to const methods are OK, if those calls are made while it 50 // is guaranteed that no thread may call a non-const method. 51 // 52 // The logical function signature is: 53 // ((unknown): f32[1,2], (unknown): s64[3,4]) -> (u32[5,6]) 54 // 55 // Memory stats: 56 // arg bytes total: 104 57 // arg bytes aligned: 128 58 // temp bytes total: 126 59 // temp bytes aligned: 224 60 class MyClass : public tensorflow::XlaCompiledCpuFunction { 61 public: 62 // Number of input arguments for the compiled computation. 63 static constexpr size_t kNumArgs = 2; 64 65 // Byte size of each argument buffer. There are kNumArgs entries. 66 static const intptr_t* ArgSizes() { 67 static constexpr intptr_t kArgSizes[kNumArgs] = {8, 96}; 68 return kArgSizes; 69 } 70 71 // Returns static data used to create an XlaCompiledCpuFunction. 72 static const tensorflow::XlaCompiledCpuFunction::StaticData& StaticData() { 73 static XlaCompiledCpuFunction::StaticData* kStaticData = [](){ 74 XlaCompiledCpuFunction::StaticData* data = 75 new XlaCompiledCpuFunction::StaticData; 76 data->raw_function = entry_point; 77 data->arg_sizes = ArgSizes(); 78 data->num_args = kNumArgs; 79 data->temp_sizes = TempSizes(); 80 data->num_temps = kNumTemps; 81 data->result_index = kResultIndex; 82 data->arg_names = StaticArgNames(); 83 data->result_names = StaticResultNames(); 84 data->program_shape = StaticProgramShape(); 85 return data; 86 }(); 87 return *kStaticData; 88 } 89 90 MyClass(AllocMode alloc_mode = AllocMode::ARGS_RESULTS_PROFILES_AND_TEMPS) 91 : XlaCompiledCpuFunction(StaticData(), alloc_mode) {} 92 93 MyClass(const MyClass&) = delete; 94 MyClass& operator=(const MyClass&) = delete; 95 96 // Arg methods for managing input buffers. Buffers are in row-major order. 97 // There is a set of methods for each positional argument, with the following 98 // general form: 99 // 100 // void set_argN_data(void* data) 101 // Sets the buffer of type T for positional argument N. May be called in 102 // any AllocMode. Must be called before Run to have an affect. Must be 103 // called in AllocMode::RESULTS_PROFILES_AND_TEMPS_ONLY for each positional 104 // argument, to set the argument buffers. 105 // 106 // T* argN_data() 107 // Returns the buffer of type T for positional argument N. 108 // 109 // T& argN(...dim indices...) 110 // Returns a reference to the value of type T for positional argument N, 111 // with dim indices specifying which value. No bounds checking is performed 112 // on dim indices. 113 114 void set_arg0_data(void* data) { 115 set_arg_data(0, data); 116 } 117 float* arg0_data() { 118 return static_cast<float*>(arg_data(0)); 119 } 120 float& arg0(size_t dim0, size_t dim1) { 121 return (*static_cast<float(*)[1][2]>( 122 arg_data(0)))[dim0][dim1]; 123 } 124 const float* arg0_data() const { 125 return static_cast<const float*>(arg_data(0)); 126 } 127 const float& arg0(size_t dim0, size_t dim1) const { 128 return (*static_cast<const float(*)[1][2]>( 129 arg_data(0)))[dim0][dim1]; 130 } 131 132 void set_arg_myfeed_data(void* data) { 133 set_arg_data(0, data); 134 } 135 float* arg_myfeed_data() { 136 return static_cast<float*>(arg_data(0)); 137 } 138 float& arg_myfeed(size_t dim0, size_t dim1) { 139 return (*static_cast<float(*)[1][2]>( 140 arg_data(0)))[dim0][dim1]; 141 } 142 const float* arg_myfeed_data() const { 143 return static_cast<const float*>(arg_data(0)); 144 } 145 const float& arg_myfeed(size_t dim0, size_t dim1) const { 146 return (*static_cast<const float(*)[1][2]>( 147 arg_data(0)))[dim0][dim1]; 148 } 149 150 void set_arg1_data(void* data) { 151 set_arg_data(1, data); 152 } 153 tensorflow::int64* arg1_data() { 154 return static_cast<tensorflow::int64*>(arg_data(1)); 155 } 156 tensorflow::int64& arg1(size_t dim0, size_t dim1) { 157 return (*static_cast<tensorflow::int64(*)[3][4]>( 158 arg_data(1)))[dim0][dim1]; 159 } 160 const tensorflow::int64* arg1_data() const { 161 return static_cast<const tensorflow::int64*>(arg_data(1)); 162 } 163 const tensorflow::int64& arg1(size_t dim0, size_t dim1) const { 164 return (*static_cast<const tensorflow::int64(*)[3][4]>( 165 arg_data(1)))[dim0][dim1]; 166 } 167 168 // Result methods for managing output buffers. Buffers are in row-major order. 169 // Must only be called after a successful Run call. There is a set of methods 170 // for each positional result, with the following general form: 171 // 172 // T* resultN_data() 173 // Returns the buffer of type T for positional result N. 174 // 175 // T& resultN(...dim indices...) 176 // Returns a reference to the value of type T for positional result N, 177 // with dim indices specifying which value. No bounds checking is performed 178 // on dim indices. 179 // 180 // Unlike the arg methods, there is no set_resultN_data method. The result 181 // buffers are managed internally, and may change after each call to Run. 182 183 tensorflow::uint32* result0_data() { 184 return static_cast<tensorflow::uint32*>(result_data(0)); 185 } 186 tensorflow::uint32& result0(size_t dim0, size_t dim1) { 187 return (*static_cast<tensorflow::uint32(*)[5][6]>( 188 result_data(0)))[dim0][dim1]; 189 } 190 const tensorflow::uint32* result0_data() const { 191 return static_cast<const tensorflow::uint32*>(result_data(0)); 192 } 193 const tensorflow::uint32& result0(size_t dim0, size_t dim1) const { 194 return (*static_cast<const tensorflow::uint32(*)[5][6]>( 195 result_data(0)))[dim0][dim1]; 196 } 197 198 tensorflow::uint32* result_myfetch_data() { 199 return static_cast<tensorflow::uint32*>(result_data(0)); 200 } 201 tensorflow::uint32& result_myfetch(size_t dim0, size_t dim1) { 202 return (*static_cast<tensorflow::uint32(*)[5][6]>( 203 result_data(0)))[dim0][dim1]; 204 } 205 const tensorflow::uint32* result_myfetch_data() const { 206 return static_cast<const tensorflow::uint32*>(result_data(0)); 207 } 208 const tensorflow::uint32& result_myfetch(size_t dim0, size_t dim1) const { 209 return (*static_cast<const tensorflow::uint32(*)[5][6]>( 210 result_data(0)))[dim0][dim1]; 211 } 212 213 private: 214 // Number of result and temporary buffers for the compiled computation. 215 static constexpr size_t kNumTemps = 6; 216 // The 0-based index of the result tuple in the temporary buffers. 217 static constexpr size_t kResultIndex = 5; 218 219 // Byte size of each result / temporary buffer. There are kNumTemps entries. 220 static const intptr_t* TempSizes() { 221 static constexpr intptr_t kTempSizes[kNumTemps] = {1, -1, 2, -1, 3, 120}; 222 return kTempSizes; 223 } 224 225 // Array of names of each positional argument, terminated by nullptr. 226 static const char** StaticArgNames() { 227 static const char* kNames[] = {"myfeed", nullptr}; 228 return kNames; 229 } 230 231 // Array of names of each positional result, terminated by nullptr. 232 static const char** StaticResultNames() { 233 static const char* kNames[] = {"myfetch", nullptr}; 234 return kNames; 235 } 236 237 // Shape of the args and results. 238 static const xla::ProgramShape* StaticProgramShape() { 239 static const xla::ProgramShape* kShape = []() { 240 xla::ProgramShape* proto = new xla::ProgramShape; 241 proto->ParseFromArray(&__tfcompile_foo_bar_MyClass_ProgramShape_protobuf_array_contents[0], 52); 242 return proto; 243 }(); 244 return kShape; 245 } 246 }; 247 248 } // end namespace bar 249 } // end namespace foo 250 251 #endif // TFCOMPILE_GENERATED_entry_point_H_ 252 253 // clang-format on 254