aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/compiler/aot/codegen_test_h.golden
blob: e4d8a02877c75fa72c5747650ab9c7ac229955b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
// Generated by tfcompile, the TensorFlow graph compiler.  DO NOT EDIT!
//
// This header was generated via ahead-of-time compilation of a TensorFlow
// graph.  An object file corresponding to this header was also generated.
// This header gives access to the functionality in that object file.
//
// clang-format off

#ifndef TFCOMPILE_GENERATED_entry_point_H_  // NOLINT(build/header_guard)
#define TFCOMPILE_GENERATED_entry_point_H_  // NOLINT(build/header_guard)

#include "tensorflow/compiler/xla/xla_data.pb.h"

#include "tensorflow/compiler/tf2xla/xla_compiled_cpu_function.h"
#include "tensorflow/core/platform/types.h"

namespace Eigen { struct ThreadPoolDevice; }
namespace xla { class ExecutableRunOptions; }

// (Implementation detail) Entry point to the function in the object file.
extern "C" void entry_point(
    void* result, const xla::ExecutableRunOptions* run_options,
    const void** args, void** temps, tensorflow::int64* profile_counters);

extern "C" char __tfcompile_foo_bar_MyClass_ProgramShape_protobuf_array_contents[];


namespace foo {
namespace bar {

// MyClass represents a computation previously specified in a
// TensorFlow graph, now compiled into executable code. This extends the generic
// XlaCompiledCpuFunction class with statically type-safe arg and result
// methods. Usage example:
//
//   MyClass computation;
//   // ...set args using computation.argN methods
//   CHECK(computation.Run());
//   // ...inspect results using computation.resultN methods
//
// The Run method invokes the actual computation, with inputs read from arg
// buffers, and outputs written to result buffers. Each Run call may also use
// a set of temporary buffers for the computation.
//
// By default each instance of this class manages its own arg, result and temp
// buffers. The AllocMode constructor parameter may be used to modify the
// buffer allocation strategy.
//
// Under the default allocation strategy, this class is thread-compatible:
// o Calls to non-const methods require exclusive access to the object.
// o Concurrent calls to const methods are OK, if those calls are made while it
//   is guaranteed that no thread may call a non-const method.
//
// The logical function signature is:
//   ((unknown): f32[1,2], (unknown): s64[3,4]) -> (u32[5,6])
//
// Memory stats:
//   arg bytes total:    104
//   arg bytes aligned:  192
//   temp bytes total:   126
//   temp bytes aligned: 320
class MyClass : public tensorflow::XlaCompiledCpuFunction {
 public:
  // Number of input arguments for the compiled computation.
  static constexpr size_t kNumArgs = 2;

  // Byte size of each argument buffer. There are kNumArgs entries.
  static const ::tensorflow::int64 ArgSize(::tensorflow::int32 index) {
    return BufferInfos()[ArgIndexToBufferIndex()[index]].size();
  }

  // Returns static data used to create an XlaCompiledCpuFunction.
  static const tensorflow::XlaCompiledCpuFunction::StaticData& StaticData() {
    static XlaCompiledCpuFunction::StaticData* kStaticData = [](){
      XlaCompiledCpuFunction::StaticData* data =
        new XlaCompiledCpuFunction::StaticData;
      data->set_raw_function(entry_point);
      data->set_buffer_infos(BufferInfos());
      data->set_num_buffers(kNumBuffers);
      data->set_arg_index_table(ArgIndexToBufferIndex());
      data->set_num_args(kNumArgs);
      data->set_result_index(kResultIndex);
      data->set_arg_names(StaticArgNames());
      data->set_result_names(StaticResultNames());
      data->set_program_shape(StaticProgramShape());
      data->set_hlo_profile_printer_data(StaticHloProfilePrinterData());

      return data;
    }();
    return *kStaticData;
  }

  MyClass(AllocMode alloc_mode = AllocMode::ARGS_RESULTS_PROFILES_AND_TEMPS)
      : XlaCompiledCpuFunction(StaticData(), alloc_mode) {}

  MyClass(const MyClass&) = delete;
  MyClass& operator=(const MyClass&) = delete;

  // Arg methods for managing input buffers. Buffers are in row-major order.
  // There is a set of methods for each positional argument, with the following
  // general form:
  //
  // void set_argN_data(void* data)
  //   Sets the buffer of type T for positional argument N. May be called in
  //   any AllocMode. Must be called before Run to have an affect. Must be
  //   called in AllocMode::RESULTS_PROFILES_AND_TEMPS_ONLY for each positional
  //   argument, to set the argument buffers.
  //
  // T* argN_data()
  //   Returns the buffer of type T for positional argument N.
  //
  // T& argN(...dim indices...)
  //   Returns a reference to the value of type T for positional argument N,
  //   with dim indices specifying which value. No bounds checking is performed
  //   on dim indices.

  void set_arg0_data(void* data) {
    set_arg_data(0, data);
  }
  float* arg0_data() {
    return static_cast<float*>(arg_data(0));
  }
  float& arg0(size_t dim0, size_t dim1) {
    return (*static_cast<float(*)[1][2]>(
        arg_data(0)))[dim0][dim1];
  }
  const float* arg0_data() const {
    return static_cast<const float*>(arg_data(0));
  }
  const float& arg0(size_t dim0, size_t dim1) const {
    return (*static_cast<const float(*)[1][2]>(
        arg_data(0)))[dim0][dim1];
  }

  void set_arg_myfeed_data(void* data) {
    set_arg_data(0, data);
  }
  float* arg_myfeed_data() {
    return static_cast<float*>(arg_data(0));
  }
  float& arg_myfeed(size_t dim0, size_t dim1) {
    return (*static_cast<float(*)[1][2]>(
        arg_data(0)))[dim0][dim1];
  }
  const float* arg_myfeed_data() const {
    return static_cast<const float*>(arg_data(0));
  }
  const float& arg_myfeed(size_t dim0, size_t dim1) const {
    return (*static_cast<const float(*)[1][2]>(
        arg_data(0)))[dim0][dim1];
  }

  void set_arg1_data(void* data) {
    set_arg_data(1, data);
  }
  tensorflow::int64* arg1_data() {
    return static_cast<tensorflow::int64*>(arg_data(1));
  }
  tensorflow::int64& arg1(size_t dim0, size_t dim1) {
    return (*static_cast<tensorflow::int64(*)[3][4]>(
        arg_data(1)))[dim0][dim1];
  }
  const tensorflow::int64* arg1_data() const {
    return static_cast<const tensorflow::int64*>(arg_data(1));
  }
  const tensorflow::int64& arg1(size_t dim0, size_t dim1) const {
    return (*static_cast<const tensorflow::int64(*)[3][4]>(
        arg_data(1)))[dim0][dim1];
  }

  // Result methods for managing output buffers. Buffers are in row-major order.
  // Must only be called after a successful Run call. There is a set of methods
  // for each positional result, with the following general form:
  //
  // T* resultN_data()
  //   Returns the buffer of type T for positional result N.
  //
  // T& resultN(...dim indices...)
  //   Returns a reference to the value of type T for positional result N,
  //   with dim indices specifying which value. No bounds checking is performed
  //   on dim indices.
  //
  // Unlike the arg methods, there is no set_resultN_data method. The result
  // buffers are managed internally, and may change after each call to Run.

  tensorflow::uint32* result0_data() {
    return static_cast<tensorflow::uint32*>(result_data(0));
  }
  tensorflow::uint32& result0(size_t dim0, size_t dim1) {
    return (*static_cast<tensorflow::uint32(*)[5][6]>(
        result_data(0)))[dim0][dim1];
  }
  const tensorflow::uint32* result0_data() const {
    return static_cast<const tensorflow::uint32*>(result_data(0));
  }
  const tensorflow::uint32& result0(size_t dim0, size_t dim1) const {
    return (*static_cast<const tensorflow::uint32(*)[5][6]>(
        result_data(0)))[dim0][dim1];
  }

  tensorflow::uint32* result_myfetch_data() {
    return static_cast<tensorflow::uint32*>(result_data(0));
  }
  tensorflow::uint32& result_myfetch(size_t dim0, size_t dim1) {
    return (*static_cast<tensorflow::uint32(*)[5][6]>(
        result_data(0)))[dim0][dim1];
  }
  const tensorflow::uint32* result_myfetch_data() const {
    return static_cast<const tensorflow::uint32*>(result_data(0));
  }
  const tensorflow::uint32& result_myfetch(size_t dim0, size_t dim1) const {
    return (*static_cast<const tensorflow::uint32(*)[5][6]>(
        result_data(0)))[dim0][dim1];
  }

 private:
  // Number of buffers for the compiled computation.
  static constexpr size_t kNumBuffers = 6;

  static const ::tensorflow::cpu_function_runtime::BufferInfo* BufferInfos() {
    static const ::tensorflow::cpu_function_runtime::BufferInfo
      kBufferInfos[kNumBuffers] = {
::tensorflow::cpu_function_runtime::BufferInfo({5ULL, ~0ULL}),
::tensorflow::cpu_function_runtime::BufferInfo({34ULL, 0ULL}),
::tensorflow::cpu_function_runtime::BufferInfo({9ULL, ~0ULL}),
::tensorflow::cpu_function_runtime::BufferInfo({386ULL, 1ULL}),
::tensorflow::cpu_function_runtime::BufferInfo({13ULL, ~0ULL}),
::tensorflow::cpu_function_runtime::BufferInfo({481ULL, ~0ULL})
      };
    return kBufferInfos;
  }

  static const ::tensorflow::int32* ArgIndexToBufferIndex() {
    static constexpr ::tensorflow::int32 kArgIndexToBufferIndex[kNumArgs] = {
1, 3
    };
    return kArgIndexToBufferIndex;
  }

  // The 0-based index of the result tuple in the temporary buffers.
  static constexpr size_t kResultIndex = 5;

  // Array of names of each positional argument, terminated by nullptr.
  static const char** StaticArgNames() {
    static const char* kNames[] = {"myfeed", nullptr};
    return kNames;
  }

  // Array of names of each positional result, terminated by nullptr.
  static const char** StaticResultNames() {
    static const char* kNames[] = {"myfetch", nullptr};
    return kNames;
  }

  // Shape of the args and results.
  static const xla::ProgramShape* StaticProgramShape() {
    static const xla::ProgramShape* kShape = []() {
    xla::ProgramShape* proto = new xla::ProgramShape;
    proto->ParseFromArray(&__tfcompile_foo_bar_MyClass_ProgramShape_protobuf_array_contents[0], 52);
    return proto;
  }();
    return kShape;
  }

  // Metadata that can be used to pretty-print profile counters.
  static const xla::HloProfilePrinterData* StaticHloProfilePrinterData() {
    static const xla::HloProfilePrinterData* kHloProfilePrinterData =
      nullptr;
    return kHloProfilePrinterData;
  }
};

}  // end namespace bar
}  // end namespace foo

#endif  // TFCOMPILE_GENERATED_entry_point_H_

// clang-format on