• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef TENSORFLOW_C_EAGER_C_API_TEST_UTIL_H_
16 #define TENSORFLOW_C_EAGER_C_API_TEST_UTIL_H_
17 
18 #include "tensorflow/c/eager/c_api.h"
19 #include "tensorflow/core/platform/tstring.h"
20 #include "tensorflow/core/platform/types.h"
21 #include "tensorflow/core/protobuf/tensorflow_server.pb.h"
22 
23 // Return a tensor handle containing a float scalar
24 TFE_TensorHandle* TestScalarTensorHandle(TFE_Context* ctx, float value);
25 
26 // Return a tensor handle containing a int scalar
27 TFE_TensorHandle* TestScalarTensorHandle(TFE_Context* ctx, int value);
28 
29 // Return a tensor handle containing a bool scalar
30 TFE_TensorHandle* TestScalarTensorHandle(TFE_Context* ctx, bool value);
31 
32 // Return a tensor handle containing a tstring scalar
33 TFE_TensorHandle* TestScalarTensorHandle(TFE_Context* ctx,
34                                          const tensorflow::tstring& value);
35 
36 // Return a tensor handle containing a 2x2 matrix of doubles
37 TFE_TensorHandle* DoubleTestMatrixTensorHandle(TFE_Context* ctx);
38 
39 // Return a tensor handle containing a 2x2 matrix of floats
40 TFE_TensorHandle* TestMatrixTensorHandle(TFE_Context* ctx);
41 
42 // Return a tensor handle containing 2D matrix containing given data and
43 // dimensions
44 TFE_TensorHandle* TestMatrixTensorHandleWithInput(TFE_Context* ctx,
45                                                   float data[], int64_t dims[],
46                                                   int num_dims);
47 
48 // Get a Matrix TensorHandle with given float values and dimensions
49 TFE_TensorHandle* TestTensorHandleWithDimsFloat(TFE_Context* ctx, float data[],
50                                                 int64_t dims[], int num_dims);
51 
52 // Get a Matrix TensorHandle with given int values and dimensions
53 TFE_TensorHandle* TestTensorHandleWithDimsInt(TFE_Context* ctx, int data[],
54                                               int64_t dims[], int num_dims);
55 
56 // Return a tensor handle containing a 100x100 matrix of floats
57 TFE_TensorHandle* TestMatrixTensorHandle100x100(TFE_Context* ctx);
58 
59 // Return a tensor handle containing a 3x2 matrix of doubles
60 TFE_TensorHandle* DoubleTestMatrixTensorHandle3X2(TFE_Context* ctx);
61 
62 // Return a tensor handle containing a 3x2 matrix of floats
63 TFE_TensorHandle* TestMatrixTensorHandle3X2(TFE_Context* ctx);
64 
65 // Return a variable handle referring to a variable with the given initial value
66 // on the given device.
67 TFE_TensorHandle* TestVariable(TFE_Context* ctx, float value,
68                                const tensorflow::string& device_name = "");
69 
70 // Return an add op multiplying `a` by `b`.
71 TFE_Op* AddOp(TFE_Context* ctx, TFE_TensorHandle* a, TFE_TensorHandle* b);
72 
73 // Return a matmul op multiplying `a` by `b`.
74 TFE_Op* MatMulOp(TFE_Context* ctx, TFE_TensorHandle* a, TFE_TensorHandle* b);
75 
76 // Return an identity op.
77 TFE_Op* IdentityOp(TFE_Context* ctx, TFE_TensorHandle* a);
78 
79 // Return a shape op fetching the shape of `a`.
80 TFE_Op* ShapeOp(TFE_Context* ctx, TFE_TensorHandle* a);
81 
82 // Return an 1-D INT32 tensor containing a single value 1.
83 TFE_TensorHandle* TestAxisTensorHandle(TFE_Context* ctx);
84 
85 // Return an op taking minimum of `input` long `axis` dimension.
86 TFE_Op* MinOp(TFE_Context* ctx, TFE_TensorHandle* input,
87               TFE_TensorHandle* axis);
88 
89 // If there is a device of type `device_type`, returns true
90 // and sets 'device_name' accordingly.
91 // `device_type` must be either "GPU" or "TPU".
92 bool GetDeviceName(TFE_Context* ctx, tensorflow::string* device_name,
93                    const char* device_type);
94 
95 // Create a ServerDef with the given `job_name` and add `num_tasks` tasks in it.
96 tensorflow::ServerDef GetServerDef(const tensorflow::string& job_name,
97                                    int num_tasks);
98 
99 // Create a ServerDef with job name "localhost" and add `num_tasks` tasks in it.
100 tensorflow::ServerDef GetServerDef(int num_tasks);
101 
102 #endif  // TENSORFLOW_C_EAGER_C_API_TEST_UTIL_H_
103