Skip to content

Commit b2b8729

Browse files
authored
control dparray to create device memory (#889)
* control dparray to create device memory
1 parent 52f8655 commit b2b8729

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

dpnp/backend/src/memory_sycl.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@
3030
#include <dpnp_iface.hpp>
3131
#include "queue_sycl.hpp"
3232

33+
34+
static bool use_sycl_device_memory()
35+
{
36+
// TODO need to move all getenv() into common dpnpc place
37+
const char* dpnpc_memtype_device = getenv("DPNPC_OUTPUT_DPARRAY_USE_MEMORY_DEVICE");
38+
if (dpnpc_memtype_device != nullptr)
39+
{
40+
return true;
41+
}
42+
43+
return false;
44+
}
45+
3346
// This variable is needed for the NumPy corner case
3447
// if we have zero memory array (ex. shape=(0,10)) we must keep the pointer to somewhere
3548
// memory of this variable must not be used
@@ -42,7 +55,12 @@ char* dpnp_memory_alloc_c(size_t size_in_bytes)
4255
//std::cout << "dpnp_memory_alloc_c(size=" << size_in_bytes << std::flush;
4356
if (size_in_bytes > 0)
4457
{
45-
array = reinterpret_cast<char*>(malloc_shared(size_in_bytes, DPNP_QUEUE));
58+
cl::sycl::usm::alloc memory_type = cl::sycl::usm::alloc::shared;
59+
if (use_sycl_device_memory())
60+
{
61+
memory_type = cl::sycl::usm::alloc::device;
62+
}
63+
array = reinterpret_cast<char*>(malloc(size_in_bytes, DPNP_QUEUE, memory_type));
4664
if (array == nullptr)
4765
{
4866
// TODO add information about number of allocated bytes

0 commit comments

Comments
 (0)