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

Function TEST_F

tensorflow/c/kernels_test.cc:348–385  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

346REGISTER_OP("AllocateOutputOp1").Output("output1: float");
347
348TEST_F(DeviceKernelOpTest, TestAllocateOutputSizeOne) {
349 auto my_compute_func = [](void* kernel, TF_OpKernelContext* ctx) {
350 // Allocate output
351 int64_t dim = 1;
352 size_t tensor_size_bytes = TF_DataTypeSize(TF_FLOAT);
353 TF_Tensor* output = TF_AllocateOutput(
354 /*context=*/ctx, /*index=*/0, /*dtype=*/TF_FLOAT, /*dims=*/&dim,
355 /*num_dims=*/1, /*len=*/tensor_size_bytes);
356 EXPECT_EQ(TF_FLOAT, TF_TensorType(output));
357 EXPECT_EQ(1, TF_NumDims(output));
358 EXPECT_EQ(1, TF_Dim(output, 0));
359
360 // Set output to 3
361 float* data = reinterpret_cast<float*>(TF_TensorData(output));
362 float value = 3.0f;
363#if GOOGLE_CUDA
364 OpKernelContext* cc_ctx = reinterpret_cast<OpKernelContext*>(ctx);
365 cc_ctx->eigen_gpu_device().memcpyHostToDevice(data, &value,
366 tensor_size_bytes);
367#else
368 *data = value;
369#endif
370
371 TF_Status* s = TF_NewStatus();
372 TF_SetOutput(ctx, 0, output, s);
373 EXPECT_EQ(TF_OK, TF_GetCode(s));
374
375 TF_DeleteStatus(s);
376 TF_DeleteTensor(output);
377 };
378
379 SetupOp("AllocateOutputOp1", "AllocateOutput1", my_compute_func);
380
381 TF_ASSERT_OK(RunOpKernel());
382 Tensor* output = GetOutput(0);
383 EXPECT_EQ("Tensor<type: float shape: [1] values: 3>",
384 output->DebugString(100));
385}
386
387REGISTER_OP("AllocateOutputOp0").Output("output1: float");
388

Callers

nothing calls this directly

Calls 13

TF_DataTypeSizeFunction · 0.85
TF_AllocateOutputFunction · 0.85
TF_TensorTypeFunction · 0.85
TF_NumDimsFunction · 0.85
TF_DimFunction · 0.85
TF_TensorDataFunction · 0.85
TF_NewStatusFunction · 0.85
TF_SetOutputFunction · 0.85
TF_GetCodeFunction · 0.85
TF_DeleteStatusFunction · 0.85
TF_DeleteTensorFunction · 0.85
GetOutputFunction · 0.85

Tested by

no test coverage detected