@@ -57,11 +57,17 @@ void *malloc_host(impl::engine_t *engine, size_t size) {
5757 size_t , cl_uint, cl_int *);
5858
5959 if (size == 0 ) return nullptr ;
60+ bool large_buffer = size
61+ > utils::downcast<const xpu::ocl::engine_impl_t *>(engine->impl ())
62+ ->max_allocation_size ();
63+ static cl_bitfield properties[]
64+ = {CL_MEM_FLAGS_INTEL, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL, 0 };
6065
6166 static xpu::ocl::ext_func_t <clHostMemAllocINTEL_func_t> ext_func (
6267 " clHostMemAllocINTEL" );
6368 cl_int err;
64- void *p = ext_func (engine, get_ocl_context (engine), nullptr , size, 0 , &err);
69+ void *p = ext_func (engine, get_ocl_context (engine),
70+ large_buffer ? properties : nullptr , size, 0 , &err);
6571 assert (utils::one_of (err, CL_SUCCESS, CL_OUT_OF_RESOURCES,
6672 CL_OUT_OF_HOST_MEMORY, CL_INVALID_BUFFER_SIZE));
6773 return p;
@@ -72,12 +78,17 @@ void *malloc_device(impl::engine_t *engine, size_t size) {
7278 cl_ulong *, size_t , cl_uint, cl_int *);
7379
7480 if (size == 0 ) return nullptr ;
81+ bool large_buffer = size
82+ > utils::downcast<const xpu::ocl::engine_impl_t *>(engine->impl ())
83+ ->max_allocation_size ();
84+ static cl_bitfield properties[]
85+ = {CL_MEM_FLAGS_INTEL, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL, 0 };
7586
7687 static xpu::ocl::ext_func_t <clDeviceMemAllocINTEL_func_t> ext_func (
7788 " clDeviceMemAllocINTEL" );
7889 cl_int err;
7990 void *p = ext_func (engine, get_ocl_context (engine), get_ocl_device (engine),
80- nullptr , size, 0 , &err);
91+ large_buffer ? properties : nullptr , size, 0 , &err);
8192 assert (utils::one_of (err, CL_SUCCESS, CL_OUT_OF_RESOURCES,
8293 CL_OUT_OF_HOST_MEMORY, CL_INVALID_BUFFER_SIZE));
8394 return p;
@@ -88,12 +99,17 @@ void *malloc_shared(impl::engine_t *engine, size_t size) {
8899 cl_ulong *, size_t , cl_uint, cl_int *);
89100
90101 if (size == 0 ) return nullptr ;
102+ bool large_buffer = size
103+ > utils::downcast<const xpu::ocl::engine_impl_t *>(engine->impl ())
104+ ->max_allocation_size ();
105+ static cl_bitfield properties[]
106+ = {CL_MEM_FLAGS_INTEL, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL, 0 };
91107
92108 static xpu::ocl::ext_func_t <clSharedMemAllocINTEL_func_t> ext_func (
93109 " clSharedMemAllocINTEL" );
94110 cl_int err;
95111 void *p = ext_func (engine, get_ocl_context (engine), get_ocl_device (engine),
96- nullptr , size, 0 , &err);
112+ large_buffer ? properties : nullptr , size, 0 , &err);
97113 assert (utils::one_of (err, CL_SUCCESS, CL_OUT_OF_RESOURCES,
98114 CL_OUT_OF_HOST_MEMORY, CL_INVALID_BUFFER_SIZE));
99115 return p;
0 commit comments