Commit 3a43bdac authored by shssf's avatar shssf Committed by Robert Kimball

IntelGPUBackend: create_tensor functionality implementation with Intel clDNN (#1168)

* IntelGPUBackend: create_tensor

* 9 tests are passes. List updated
parent 09adba0c
...@@ -16,12 +16,16 @@ ...@@ -16,12 +16,16 @@
set(SRC set(SRC
intelgpu_backend.cpp intelgpu_backend.cpp
intelgpu_tensor_view.cpp
) )
if (NGRAPH_INTELGPU_ENABLE) if (NGRAPH_INTELGPU_ENABLE)
add_library(intelgpu_backend SHARED ${SRC}) add_library(intelgpu_backend SHARED ${SRC})
set_target_properties(intelgpu_backend PROPERTIES VERSION ${NGRAPH_VERSION} SOVERSION ${NGRAPH_API_VERSION}) set_target_properties(intelgpu_backend PROPERTIES VERSION ${NGRAPH_VERSION} SOVERSION ${NGRAPH_API_VERSION})
target_link_libraries(intelgpu_backend PUBLIC ngraph) target_link_libraries(intelgpu_backend PUBLIC ngraph)
find_package(CLDNN REQUIRED)
target_include_directories(intelgpu_backend SYSTEM PUBLIC ${CLDNN_INCLUDE_DIRS})
target_link_libraries(intelgpu_backend PUBLIC ${CLDNN_LIBRARIES})
install(TARGETS intelgpu_backend LIBRARY DESTINATION ${NGRAPH_INSTALL_LIB}) install(TARGETS intelgpu_backend LIBRARY DESTINATION ${NGRAPH_INSTALL_LIB})
endif() endif()
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*******************************************************************************/ *******************************************************************************/
#include "ngraph/runtime/intelgpu/intelgpu_backend.hpp" #include "ngraph/runtime/intelgpu/intelgpu_backend.hpp"
#include "ngraph/runtime/intelgpu/intelgpu_tensor_view.hpp"
using namespace std; using namespace std;
using namespace ngraph; using namespace ngraph;
...@@ -25,17 +26,23 @@ extern "C" void create_backend(void) ...@@ -25,17 +26,23 @@ extern "C" void create_backend(void)
make_shared<runtime::intelgpu::IntelGPUBackend>()); make_shared<runtime::intelgpu::IntelGPUBackend>());
}; };
runtime::intelgpu::IntelGPUBackend::IntelGPUBackend()
{
ocl_engine = std::make_shared<cldnn::engine>();
}
shared_ptr<runtime::TensorView> shared_ptr<runtime::TensorView>
runtime::intelgpu::IntelGPUBackend::create_tensor(const element::Type& element_type, runtime::intelgpu::IntelGPUBackend::create_tensor(const element::Type& element_type,
const Shape& shape) const Shape& shape)
{ {
throw runtime_error("IntelGPUBackend::create_tensor: Not implemented yet"); return make_shared<runtime::intelgpu::IntelGPUTensorView>(element_type, shape, *ocl_engine);
} }
shared_ptr<runtime::TensorView> runtime::intelgpu::IntelGPUBackend::create_tensor( shared_ptr<runtime::TensorView> runtime::intelgpu::IntelGPUBackend::create_tensor(
const element::Type& element_type, const Shape& shape, void* memory_pointer) const element::Type& element_type, const Shape& shape, void* memory_pointer)
{ {
throw runtime_error("IntelGPUBackend::create_tensor: Not implemented yet"); return make_shared<runtime::intelgpu::IntelGPUTensorView>(
element_type, shape, *ocl_engine, memory_pointer);
} }
bool runtime::intelgpu::IntelGPUBackend::compile(shared_ptr<Function> func) bool runtime::intelgpu::IntelGPUBackend::compile(shared_ptr<Function> func)
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
#pragma once #pragma once
#include <map> #include <map>
#include <memory>
#include <CPP/engine.hpp>
#include "ngraph/runtime/backend.hpp" #include "ngraph/runtime/backend.hpp"
...@@ -34,6 +37,7 @@ namespace ngraph ...@@ -34,6 +37,7 @@ namespace ngraph
class ngraph::runtime::intelgpu::IntelGPUBackend : public runtime::Backend class ngraph::runtime::intelgpu::IntelGPUBackend : public runtime::Backend
{ {
public: public:
IntelGPUBackend();
std::shared_ptr<ngraph::runtime::TensorView> std::shared_ptr<ngraph::runtime::TensorView>
create_tensor(const ngraph::element::Type& element_type, create_tensor(const ngraph::element::Type& element_type,
const Shape& shape, const Shape& shape,
...@@ -49,4 +53,5 @@ public: ...@@ -49,4 +53,5 @@ public:
const std::vector<std::shared_ptr<runtime::TensorView>>& inputs) override; const std::vector<std::shared_ptr<runtime::TensorView>>& inputs) override;
private: private:
std::shared_ptr<cldnn::engine> ocl_engine;
}; };
/*******************************************************************************
* Copyright 2017-2018 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
#include <memory>
#include <CPP/data.hpp>
#include "ngraph/descriptor/layout/dense_tensor_view_layout.hpp"
#include "ngraph/descriptor/primary_tensor_view.hpp"
#include "ngraph/runtime/intelgpu/intelgpu_tensor_view.hpp"
#include "ngraph/shape.hpp"
using namespace ngraph;
using namespace std;
runtime::intelgpu::IntelGPUTensorView::IntelGPUTensorView(const ngraph::element::Type& element_type,
const Shape& shape,
const cldnn::engine& backend_engine,
void* memory_pointer)
: runtime::TensorView(std::make_shared<ngraph::descriptor::PrimaryTensorView>(
std::make_shared<ngraph::TensorViewType>(element_type, shape), "external"))
{
m_descriptor->set_tensor_view_layout(
std::make_shared<ngraph::descriptor::layout::DenseTensorViewLayout>(*m_descriptor));
size_t mem_size = shape_size(shape);
cldnn::data_types data_type = get_cldnn_type(element_type);
cldnn::tensor tensor(1, mem_size, 1, 1);
cldnn::format::type format = cldnn::format::yxfb;
cldnn::layout layout(data_type, format, tensor);
if (nullptr != memory_pointer)
{
ocl_memory = make_shared<cldnn::memory>(
cldnn::memory::attach<void>(layout, memory_pointer, layout.get_linear_size()));
}
else
{
ocl_memory = make_shared<cldnn::memory>(cldnn::memory::allocate(backend_engine, layout));
}
}
void runtime::intelgpu::IntelGPUTensorView::write(const void* source,
size_t tensor_offset,
size_t n)
{
if (tensor_offset + n > ocl_memory->size())
{
throw out_of_range("write access past end of tensor");
}
auto ptr = ocl_memory->pointer<char>();
char* target = ptr.data();
memcpy(&target[tensor_offset], source, n);
}
void runtime::intelgpu::IntelGPUTensorView::read(void* target, size_t tensor_offset, size_t n) const
{
if (tensor_offset + n > ocl_memory->size())
{
throw out_of_range("read access past end of tensor");
}
const auto ptr = ocl_memory->pointer<char>();
const char* source = ptr.data();
memcpy(target, &source[tensor_offset], n);
}
cldnn::data_types runtime::intelgpu::IntelGPUTensorView::get_cldnn_type(
const ngraph::element::Type& element_type) const
{
if (element_type == ngraph::element::i8)
{
return cldnn::data_types::i8;
}
else if (element_type == ngraph::element::u8)
{
return cldnn::data_types::u8;
}
else if (element_type == ngraph::element::f32)
{
return cldnn::data_types::f32;
}
else
{
ostringstream os;
os << "IntelGPUTensorView::get_cldnn_type: Unknown type " << element_type;
throw std::invalid_argument(os.str());
}
}
/*******************************************************************************
* Copyright 2017-2018 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
#pragma once
#include <CPP/engine.hpp>
#include <CPP/layout.hpp>
#include <CPP/memory.hpp>
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/type/element_type.hpp"
namespace ngraph
{
namespace runtime
{
namespace intelgpu
{
class IntelGPUTensorView;
}
}
}
class ngraph::runtime::intelgpu::IntelGPUTensorView : public ngraph::runtime::TensorView
{
public:
IntelGPUTensorView(const ngraph::element::Type& element_type,
const Shape& shape,
const cldnn::engine& backend_engine,
void* memory_pointer = nullptr);
/// @brief Write bytes directly into the tensor
/// @param p Pointer to source of data
/// @param tensor_offset Offset into tensor storage to begin writing. Must be element-aligned.
/// @param n Number of bytes to write, must be integral number of elements.
void write(const void* p, size_t tensor_offset, size_t n) override;
/// @brief Read bytes directly from the tensor
/// @param p Pointer to destination for data
/// @param tensor_offset Offset into tensor storage to begin reading. Must be element-aligned.
/// @param n Number of bytes to read, must be integral number of elements.
void read(void* p, size_t tensor_offset, size_t n) const override;
private:
cldnn::data_types get_cldnn_type(const ngraph::element::Type& element_type) const;
std::shared_ptr<cldnn::memory> ocl_memory;
};
...@@ -18,7 +18,6 @@ avg_pool_2d_2channel_2image_padded_3x3_strided ...@@ -18,7 +18,6 @@ avg_pool_2d_2channel_2image_padded_3x3_strided
avg_pool_2d_2channel_2image_padded_3x3_strided_uneven avg_pool_2d_2channel_2image_padded_3x3_strided_uneven
avg_pool_2d_2channel_2image_padded_only_above avg_pool_2d_2channel_2image_padded_only_above
avg_pool_2d_2channel_2image_padded_only_below avg_pool_2d_2channel_2image_padded_only_below
avg_pool_3d
backwards_abc backwards_abc
backwards_abs backwards_abs
backwards_acos backwards_acos
...@@ -52,10 +51,10 @@ backwards_exp ...@@ -52,10 +51,10 @@ backwards_exp
backwards_floor backwards_floor
backwards_log backwards_log
backwards_maximum backwards_maximum
backwards_maxpool_n2_c1_hw5_3x3_str2_max
backwards_maxpool_n2c1h5w5_kh3kw3_sh2sw2 backwards_maxpool_n2c1h5w5_kh3kw3_sh2sw2
backwards_maxpool_n4_c1_hw4_2x2_max backwards_maxpool_n2_c1_hw5_3x3_str2_max
backwards_maxpool_n4c1h4w4_kh2kw2_sh1sw1 backwards_maxpool_n4c1h4w4_kh2kw2_sh1sw1
backwards_maxpool_n4_c1_hw4_2x2_max
backwards_minimum backwards_minimum
backwards_multiply backwards_multiply
backwards_negative backwards_negative
...@@ -84,13 +83,13 @@ backwards_sum_m2v_1 ...@@ -84,13 +83,13 @@ backwards_sum_m2v_1
backwards_sum_v2s backwards_sum_v2s
backwards_tan backwards_tan
backwards_tanh backwards_tanh
batch_norm_one_output
batch_norm_three_outputs
batchnorm_bprop_n4c3h2w2 batchnorm_bprop_n4c3h2w2
batchnorm_fprop_b1c2h2w2 batchnorm_fprop_b1c2h2w2
batchnorm_fprop_b2c2h2w1 batchnorm_fprop_b2c2h2w1
batchnorm_fprop_globalstats_b2c2w2h1 batchnorm_fprop_globalstats_b2c2w2h1
batchnorm_fprop_inference_b2c2h2w1 batchnorm_fprop_inference_b2c2h2w1
batch_norm_one_output
batch_norm_three_outputs
broadcast_matrix_0 broadcast_matrix_0
broadcast_matrix_1 broadcast_matrix_1
broadcast_matrix_2 broadcast_matrix_2
...@@ -111,7 +110,9 @@ concat_matrix_colwise ...@@ -111,7 +110,9 @@ concat_matrix_colwise
concat_matrix_int64 concat_matrix_int64
concat_matrix_rowwise concat_matrix_rowwise
concat_vector concat_vector
constant_broadcast concat_zero_length_1d_last
concat_zero_length_1d_middle
concat_zero_length_4d_middle
constant_equality_bool constant_equality_bool
constant_multi_use constant_multi_use
convert_float32_bool convert_float32_bool
...@@ -155,12 +156,12 @@ divide ...@@ -155,12 +156,12 @@ divide
divide_adjoint_stability divide_adjoint_stability
divide_by_zero_float32 divide_by_zero_float32
divide_by_zero_int32 divide_by_zero_int32
dot_0_0
dot1d dot1d
dot2d dot2d
dot_2x0_0
dot3d_2d dot3d_2d
dot3d_3d dot3d_3d
dot_0_0
dot_2x0_0
dot_matrix_0x2_2x0 dot_matrix_0x2_2x0
dot_matrix_2x0_0x2 dot_matrix_2x0_0x2
dot_matrix_3x2_2x0 dot_matrix_3x2_2x0
...@@ -192,6 +193,7 @@ max_3d_to_matrix_least_sig ...@@ -192,6 +193,7 @@ max_3d_to_matrix_least_sig
max_3d_to_matrix_most_sig max_3d_to_matrix_most_sig
max_3d_to_scalar max_3d_to_scalar
max_3d_to_vector max_3d_to_vector
maximum
max_matrix_cols_zero max_matrix_cols_zero
max_matrix_columns max_matrix_columns
max_matrix_rows max_matrix_rows
...@@ -205,17 +207,16 @@ max_pool_2d_1channel_1image_padded ...@@ -205,17 +207,16 @@ max_pool_2d_1channel_1image_padded
max_pool_2d_1channel_1image_padded_negative_values max_pool_2d_1channel_1image_padded_negative_values
max_pool_2d_1channel_1image_strided max_pool_2d_1channel_1image_strided
max_pool_2d_2channel_2image max_pool_2d_2channel_2image
max_pool_3d
max_to_scalar max_to_scalar
max_trivial max_trivial
max_trivial_5d max_trivial_5d
max_vector_zero max_vector_zero
maximum
min_3d_eliminate_zero_dim min_3d_eliminate_zero_dim
min_3d_to_matrix_least_sig min_3d_to_matrix_least_sig
min_3d_to_matrix_most_sig min_3d_to_matrix_most_sig
min_3d_to_scalar min_3d_to_scalar
min_3d_to_vector min_3d_to_vector
minimum
min_matrix_cols_zero min_matrix_cols_zero
min_matrix_columns min_matrix_columns
min_matrix_rows min_matrix_rows
...@@ -225,7 +226,6 @@ min_to_scalar ...@@ -225,7 +226,6 @@ min_to_scalar
min_trivial min_trivial
min_trivial_5d min_trivial_5d
min_vector_zero min_vector_zero
minimum
mkldnn_layouts mkldnn_layouts
multiple_backends multiple_backends
multiple_result multiple_result
...@@ -298,6 +298,8 @@ replace_slice_3d_strided_different_strides ...@@ -298,6 +298,8 @@ replace_slice_3d_strided_different_strides
replace_slice_matrix replace_slice_matrix
replace_slice_scalar replace_slice_scalar
replace_slice_vector replace_slice_vector
reshape_3d_transpose
reshape_4d_transpose
reshape_6d reshape_6d
reshape_m2m_dim_change_transpose reshape_m2m_dim_change_transpose
reshape_m2m_same reshape_m2m_same
...@@ -331,8 +333,8 @@ scalar_constant_float32 ...@@ -331,8 +333,8 @@ scalar_constant_float32
scalar_constant_int64 scalar_constant_int64
select select
select_and_scatter_3d_without_overlap select_and_scatter_3d_without_overlap
select_and_scatter_with_overlap
select_and_scatter_without_overlap select_and_scatter_without_overlap
select_and_scatter_with_overlap
sign sign
sin sin
sinh sinh
...@@ -373,11 +375,7 @@ tensor_constant_float32 ...@@ -373,11 +375,7 @@ tensor_constant_float32
tensor_constant_int64 tensor_constant_int64
tensor_constant_with_op tensor_constant_with_op
tensorview_custom_mem tensorview_custom_mem
validate_call_input_count
validate_call_input_shape
validate_call_input_type validate_call_input_type
validate_call_output_count
validate_call_output_shape
validate_call_output_type validate_call_output_type
zero_sized_abs zero_sized_abs
zero_sized_acos zero_sized_acos
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment