[GPU] fix tensor allocation (#22551)
### Details: - *fix tensor allocation* ### Tickets: - *CVS-130946*
This commit is contained in:
parent
bd2fce78f9
commit
069bd84f60
|
|
@ -121,6 +121,7 @@ inline void ForceExit() {
|
|||
void convert_and_copy(const ov::ITensor* src, cldnn::memory::ptr dst, cldnn::stream& stream);
|
||||
void convert_and_copy(const cldnn::memory::ptr src, ov::ITensor const* dst, const cldnn::stream& stream);
|
||||
void convert_and_copy(const ov::ITensor* src, ov::ITensor const* dst, const cldnn::stream& stream);
|
||||
void convert_and_copy(const cldnn::memory::ptr src, cldnn::memory::ptr dst, cldnn::stream& stream);
|
||||
|
||||
} // namespace intel_gpu
|
||||
|
||||
|
|
|
|||
|
|
@ -138,6 +138,20 @@ void convert_and_copy(const cldnn::memory::ptr src, ov::ITensor const* dst, cons
|
|||
return ::convert_and_copy(src_ptr, src_et, dst_ptr, dst_et, size, src->get_layout());
|
||||
}
|
||||
|
||||
void convert_and_copy(const cldnn::memory::ptr src, cldnn::memory::ptr dst, cldnn::stream& stream) {
|
||||
const bool blocking = true;
|
||||
auto src_et = src->get_layout().data_type;
|
||||
auto dst_et = dst->get_layout().data_type;
|
||||
|
||||
cldnn::mem_lock<uint8_t, cldnn::mem_lock_type::read> src_lock(src, stream);
|
||||
const void* src_ptr = src_lock.data();
|
||||
|
||||
size_t size = ov::shape_size(src->get_layout().get_shape());
|
||||
ov::Tensor tmp_tensor(dst_et, src->get_layout().get_shape());
|
||||
::convert_and_copy(src_ptr, src_et, tmp_tensor.data(), dst_et, size, src->get_layout());
|
||||
dst->copy_from(stream, tmp_tensor.data(), blocking);
|
||||
}
|
||||
|
||||
void convert_and_copy(const ov::ITensor* src, ov::ITensor const* dst, const cldnn::stream& stream) {
|
||||
auto src_et = src->get_element_type();
|
||||
auto dst_et = dst->get_element_type();
|
||||
|
|
|
|||
|
|
@ -675,7 +675,13 @@ std::vector<cldnn::event::ptr> SyncInferRequest::prepare_input(const std::string
|
|||
bool convert_needed = is_convert_required(element_type, device_tensor_et);
|
||||
|
||||
if (is_remote) {
|
||||
m_plugin_inputs[name] = user_tensor_wrapper;
|
||||
if (convert_needed) {
|
||||
m_plugin_inputs[name] = { create_device_tensor(pshape,
|
||||
cldnn::element_type_to_data_type(element_type),
|
||||
false), TensorOwner::PLUGIN };
|
||||
} else {
|
||||
m_plugin_inputs[name] = user_tensor_wrapper;
|
||||
}
|
||||
} else if (is_usm_host_tensor && !convert_needed && can_use_usm_host(engine)) {
|
||||
if (element_type != cldnn::element_type_to_data_type(element_type)) {
|
||||
m_plugin_inputs[name] = {std::make_shared<RemoteTensorImpl>(m_context,
|
||||
|
|
@ -753,14 +759,17 @@ std::vector<cldnn::event::ptr> SyncInferRequest::prepare_input(const std::string
|
|||
}
|
||||
|
||||
cldnn::event::ptr ret_event = nullptr;
|
||||
if (!is_remote) {
|
||||
if (convert_needed) {
|
||||
convert_and_copy(user_tensor.get(), device_tensor.get(), stream);
|
||||
if (!is_remote && !convert_needed) {
|
||||
auto src_ptr = static_cast<uint8_t*>(user_tensor->data());
|
||||
if (!same_host_mem(memory, src_ptr)) {
|
||||
ret_event = memory->copy_from(stream, src_ptr, false);
|
||||
}
|
||||
}
|
||||
if (convert_needed) {
|
||||
if (is_remote) {
|
||||
convert_and_copy(remote_ptr->get_memory(), device_tensor->get_memory(), stream);
|
||||
} else {
|
||||
auto src_ptr = static_cast<uint8_t*>(user_tensor->data());
|
||||
if (!same_host_mem(memory, src_ptr)) {
|
||||
ret_event = memory->copy_from(stream, src_ptr, false);
|
||||
}
|
||||
convert_and_copy(user_tensor.get(), device_tensor.get(), stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue