MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / BitcastOp_Compute

Function BitcastOp_Compute

tensorflow/c/kernels/bitcast_op.cc:90–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90static void BitcastOp_Compute(void* kernel, TF_OpKernelContext* ctx) {
91 auto* k = static_cast<BitcastOp*>(kernel);
92 int dim_count = 0;
93
94 TF_Tensor* tensor;
95 TF_Status* status = TF_NewStatus();
96 TF_GetInput(ctx, 0, &tensor, status);
97 if (TF_GetCode(status) == TF_OK) {
98 dim_count = TF_NumDims(tensor);
99 if (!(k->in_size >= k->out_size ||
100 (dim_count > 0 &&
101 TF_Dim(tensor, dim_count - 1) == k->out_size / k->in_size))) {
102 std::ostringstream err;
103 err << "Cannot bitcast from " << k->input_data_type << " to "
104 << k->output_data_type;
105 TF_SetStatus(status, TF_INVALID_ARGUMENT, err.str().c_str());
106 }
107 }
108
109 if (TF_GetCode(status) == TF_OK) {
110 auto* dims = new int64_t[dim_count + 1];
111 int new_dim_count = dim_count;
112 for (int dim = 0; dim < dim_count; ++dim) {
113 dims[dim] = TF_Dim(tensor, dim);
114 }
115 if (k->out_size < k->in_size) {
116 dims[new_dim_count++] = static_cast<int64_t>(k->in_size / k->out_size);
117 } else if (k->out_size > k->in_size) {
118 --new_dim_count;
119 }
120
121 TF_Tensor* output = TF_AllocateTensor(k->output_data_type, dims, 0,
122 TF_DataTypeSize(k->output_data_type));
123 TF_TensorBitcastFrom(tensor, k->output_data_type, output, dims,
124 new_dim_count, status);
125 if (TF_GetCode(status) == TF_OK) {
126 TF_SetOutput(ctx, 0, output, status);
127 }
128 delete[] dims;
129 TF_DeleteTensor(output);
130 }
131
132 if (TF_GetCode(status) != TF_OK) {
133 TF_OpKernelContext_Failure(ctx, status);
134 }
135 TF_DeleteStatus(status);
136 TF_DeleteTensor(tensor);
137}
138
139void RegisterBitcastOpKernel() {
140 TF_Status* status = TF_NewStatus();

Callers

nothing calls this directly

Calls 14

TF_NewStatusFunction · 0.85
TF_GetInputFunction · 0.85
TF_GetCodeFunction · 0.85
TF_NumDimsFunction · 0.85
TF_DimFunction · 0.85
TF_SetStatusFunction · 0.85
TF_AllocateTensorFunction · 0.85
TF_DataTypeSizeFunction · 0.85
TF_TensorBitcastFromFunction · 0.85
TF_SetOutputFunction · 0.85
TF_DeleteTensorFunction · 0.85

Tested by

no test coverage detected