| 346 | REGISTER_OP("AllocateOutputOp1").Output("output1: float"); |
| 347 | |
| 348 | TEST_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 | |
| 387 | REGISTER_OP("AllocateOutputOp0").Output("output1: float"); |
| 388 |
nothing calls this directly
no test coverage detected