Removed implicit cast from runtime objects (#9419)

This commit is contained in:
Anton Pankratov
2021-12-24 21:14:41 +03:00
committed by GitHub
parent fa2647f965
commit 6dcbb13748
6 changed files with 16 additions and 40 deletions

View File

@@ -207,17 +207,6 @@ public:
T::type_check(*this);
return *static_cast<const T*>(this);
}
/**
* @brief Casts this Tensor object to the type T.
*
* @tparam T Type to cast to. Must represent a class derived from the Tensor
* @return T object
*/
template <typename T, typename = typename std::enable_if<std::is_base_of<Tensor, T>::value>::type>
operator T() const {
return as<T>();
}
};
using TensorVector = std::vector<Tensor>;

View File

@@ -70,7 +70,7 @@ public:
* @brief Checks that type defined runtime paramters are presented in remote object
* @param remote_tensor remote tensor to check
*/
static void type_check(const RemoteTensor& remote_tensor) {
static void type_check(const Tensor& remote_tensor) {
RemoteTensor::type_check(remote_tensor,
{{GPU_PARAM_KEY(DEV_OBJECT_HANDLE), {}},
{GPU_PARAM_KEY(VA_PLANE), {}},
@@ -138,7 +138,7 @@ public:
{GPU_PARAM_KEY(VA_DEVICE), static_cast<gpu_handle_param>(device)},
{GPU_PARAM_KEY(TILE_ID), target_tile_id}
};
*this = core.create_context(device_name, context_params);
*this = core.create_context(device_name, context_params).as<D3DContext>();
}
/**
@@ -157,7 +157,7 @@ public:
tensor_params[GPU_PARAM_KEY(MEM_HANDLE)] = static_cast<gpu_handle_param>(nv12_surf);
tensor_params[GPU_PARAM_KEY(VA_PLANE)] = uint32_t(1);
auto uv_tensor = create_tensor(element::u8, {1, 2, height / 2, width / 2}, tensor_params);
return std::make_pair(y_tensor, uv_tensor);
return std::make_pair(y_tensor.as<D3DSurface2DTensor>(), uv_tensor.as<D3DSurface2DTensor>());
}
/**
@@ -170,7 +170,7 @@ public:
D3DBufferTensor create_tensor(const element::Type type, const Shape& shape, ID3D11Buffer* buffer) {
ParamMap params = {{GPU_PARAM_KEY(SHARED_MEM_TYPE), GPU_PARAM_VALUE(DX_BUFFER)},
{GPU_PARAM_KEY(DEV_OBJECT_HANDLE), static_cast<gpu_handle_param>(buffer)}};
create_tensor(type, shape, params);
create_tensor(type, shape, params).as<D3DBufferTensor>();
}
/**
@@ -189,7 +189,7 @@ public:
ParamMap params = {{GPU_PARAM_KEY(SHARED_MEM_TYPE), GPU_PARAM_VALUE(VA_SURFACE)},
{GPU_PARAM_KEY(DEV_OBJECT_HANDLE), static_cast<gpu_handle_param>(surface)},
{GPU_PARAM_KEY(VA_PLANE), plane}};
return create_tensor(type, shape, params);
return create_tensor(type, shape, params).as<D3DSurface2DTensor>();
}
};
} // namespace ocl

View File

@@ -183,7 +183,7 @@ public:
ParamMap context_params = {{GPU_PARAM_KEY(CONTEXT_TYPE), GPU_PARAM_VALUE(OCL)},
{GPU_PARAM_KEY(OCL_CONTEXT), static_cast<gpu_handle_param>(ctx)},
{GPU_PARAM_KEY(OCL_CONTEXT_DEVICE_ID), ctx_device_id}};
*this = core.create_context(device_name, context_params);
*this = core.create_context(device_name, context_params).as<ClContext>();
}
/**
@@ -200,7 +200,7 @@ public:
ParamMap context_params = {{GPU_PARAM_KEY(CONTEXT_TYPE), GPU_PARAM_VALUE(OCL)},
{GPU_PARAM_KEY(OCL_CONTEXT), static_cast<gpu_handle_param>(ctx)},
{GPU_PARAM_KEY(OCL_QUEUE), static_cast<gpu_handle_param>(queue)}};
*this = core.create_context(device_name, context_params);
*this = core.create_context(device_name, context_params).as<ClContext>();
}
/**
@@ -243,7 +243,7 @@ public:
auto y_tensor = create_tensor(element::u8, {1, 1, height, width}, tensor_params);
tensor_params[GPU_PARAM_KEY(MEM_HANDLE)] = static_cast<gpu_handle_param>(nv12_image_plane_uv.get());
auto uv_tensor = create_tensor(element::u8, {1, 2, height / 2, width / 2}, tensor_params);
return std::make_pair(y_tensor, uv_tensor);
return std::make_pair(y_tensor.as<ClImage2DTensor>(), uv_tensor.as<ClImage2DTensor>());
}
/**
@@ -256,7 +256,7 @@ public:
ClBufferTensor create_tensor(const element::Type type, const Shape& shape, const cl_mem buffer) {
ParamMap params = {{GPU_PARAM_KEY(SHARED_MEM_TYPE), GPU_PARAM_VALUE(OCL_BUFFER)},
{GPU_PARAM_KEY(MEM_HANDLE), static_cast<gpu_handle_param>(buffer)}};
return create_tensor(type, shape, params);
return create_tensor(type, shape, params).as<ClBufferTensor>();
}
/**
@@ -280,7 +280,7 @@ public:
ClImage2DTensor create_tensor(const element::Type type, const Shape& shape, const cl::Image2D& image) {
ParamMap params = {{GPU_PARAM_KEY(SHARED_MEM_TYPE), GPU_PARAM_VALUE(OCL_IMAGE2D)},
{GPU_PARAM_KEY(MEM_HANDLE), static_cast<gpu_handle_param>(image.get())}};
return create_tensor(type, shape, params);
return create_tensor(type, shape, params).as<ClImage2DTensor>();
}
/**
@@ -293,7 +293,7 @@ public:
USMTensor create_tensor(const element::Type type, const Shape& shape, void* usm_ptr) {
ParamMap params = {{GPU_PARAM_KEY(SHARED_MEM_TYPE), GPU_PARAM_VALUE(USM_USER_BUFFER)},
{GPU_PARAM_KEY(MEM_HANDLE), static_cast<gpu_handle_param>(usm_ptr)}};
return create_tensor(type, shape, params);
return create_tensor(type, shape, params).as<USMTensor>();
}
/**
@@ -304,7 +304,7 @@ public:
*/
USMTensor create_usm_host_tensor(const element::Type type, const Shape& shape) {
ParamMap params = {{GPU_PARAM_KEY(SHARED_MEM_TYPE), GPU_PARAM_VALUE(USM_HOST_BUFFER)}};
return create_tensor(type, shape, params);
return create_tensor(type, shape, params).as<USMTensor>();
}
/**
@@ -315,7 +315,7 @@ public:
*/
USMTensor create_usm_device_tensor(const element::Type type, const Shape& shape) {
ParamMap params = {{GPU_PARAM_KEY(SHARED_MEM_TYPE), GPU_PARAM_VALUE(USM_DEVICE_BUFFER)}};
return create_tensor(type, shape, params);
return create_tensor(type, shape, params).as<USMTensor>();
}
};

View File

@@ -105,7 +105,7 @@ public:
ParamMap context_params = {{GPU_PARAM_KEY(CONTEXT_TYPE), GPU_PARAM_VALUE(VA_SHARED)},
{GPU_PARAM_KEY(VA_DEVICE), static_cast<gpu_handle_param>(device)},
{GPU_PARAM_KEY(TILE_ID), target_tile_id}};
*this = core.create_context(device_name, context_params);
*this = core.create_context(device_name, context_params).as<VAContext>();
}
/**
@@ -125,7 +125,7 @@ public:
auto y_tensor = create_tensor(element::u8, {1, 1, height, width}, tensor_params);
tensor_params[GPU_PARAM_KEY(VA_PLANE)] = uint32_t(1);
auto uv_tensor = create_tensor(element::u8, {1, 2, height / 2, width / 2}, tensor_params);
return std::make_pair(y_tensor, uv_tensor);
return std::make_pair(y_tensor.as<VASurfaceTensor>(), uv_tensor.as<VASurfaceTensor>());
}
/**
@@ -143,7 +143,7 @@ public:
ParamMap params = {{GPU_PARAM_KEY(SHARED_MEM_TYPE), GPU_PARAM_VALUE(VA_SURFACE)},
{GPU_PARAM_KEY(DEV_OBJECT_HANDLE), surface},
{GPU_PARAM_KEY(VA_PLANE), plane}};
return create_tensor(type, shape, params);
return create_tensor(type, shape, params).as<VASurfaceTensor>();
}
};
} // namespace ocl

View File

@@ -118,17 +118,6 @@ public:
return *static_cast<const T*>(this);
}
/**
* @brief Casts this RemoteContext object to the type T.
*
* @tparam T Type to cast to. Must represent a class derived from the RemoteContext
* @return T object
*/
template <typename T>
operator T() const {
return as<T>();
}
/**
* @brief Returns name of the device on which underlying object is allocated.
* Abstract method.

View File

@@ -23,7 +23,6 @@ TEST(RemoteTensorOVTests, throwsOnGetDeviceName) {
TEST(RemoteTensorOVTests, remoteTensorFromEmptyTensorThrow) {
ov::runtime::Tensor empty_tensor;
ov::runtime::RemoteTensor remote_tensor;
ASSERT_THROW(remote_tensor = empty_tensor, ov::Exception);
ASSERT_FALSE(empty_tensor.is<ov::runtime::RemoteTensor>());
ASSERT_THROW(empty_tensor.as<ov::runtime::RemoteTensor>(), ov::Exception);
}
@@ -31,7 +30,6 @@ TEST(RemoteTensorOVTests, remoteTensorFromEmptyTensorThrow) {
TEST(RemoteTensorOVTests, remoteTensorConvertToRemoteThrow) {
ov::runtime::Tensor tensor{ov::element::f32, {1, 2, 3, 4}};
ov::runtime::RemoteTensor remote_tensor;
ASSERT_THROW(remote_tensor = tensor, ov::Exception);
ASSERT_FALSE(tensor.is<ov::runtime::RemoteTensor>());
ASSERT_THROW(tensor.as<ov::runtime::RemoteTensor>(), ov::Exception);
}