Intel® oneAPI Data Parallel C++
Support for Intel® oneAPI DPC++ Compiler, Intel® oneAPI DPC++ Library, Intel ICX Compiler , Intel® DPC++ Compatibility Tool, and GDB*

SYCL contexts and memory access

Pascuzzi__Vincent
1,611 Views

My understanding of the cl::sycl::context is that they are used among the different devices on a system. For example, I can only access memory allocated on a given cl::sycl::device using a cl::sycl::queue that was instantiated with the cl::sycl::context associated to said device, i.e. using cl::sycl::device::get_context().

 
Is this correct?
 
A summary of my problem: I generate random numbers in one class and store put them into the memory of an Neo device using a cl::sycl::queue member variable in this class. In another class, I allocate a bunch of memory on the ‘same’(?) Neo device using a cl::sycl::queue member variable in this other class. I get the associated device in both classes with the same common static function, i.e. the same Neo device is used. There are 3-4 classes that are implemented similarly. Now, it seems in some cases that I can use a single cl::sycl::queue from an arbitrary class to access data allocated in other classes, but in other cases I can’t; I need to use the queue/context that was used to allocate the memory. Of course I can’t operate this way since I need to access data stored among multiple classes using a single queue.
 
Is there a preferred/common/proper way to achieve what I want to do? Should I have a global “queue manager” class of sorts that uses a single queue/device/context to take care of all device-side tasks? Should I be explicitly using the same context is shared among all classes? (I wouldn’t think this mattered if my understanding of contexts is correct, and there is only a single iGPU on each machine. Unless there is different memory that is not shareable among different cl::sycl::queue objects?)
 
Thanks in advance.
 
 
Vince
0 Kudos
1 Solution
GouthamK_Intel
Moderator
1,594 Views

Hi,

Thanks for reaching out to us!

My understanding of the cl::sycl::context is that they are used among the different devices on a system. For example, I can only access memory allocated on a given cl::sycl::device using a cl::sycl::queue that was instantiated with the cl::sycl::context associated to said device, i.e. using cl::sycl::device::get_context().

When you create multiple queues even with the same device, multiple contexts get created. As they are two different SYCL contexts and any buffer you create will be a part of that context.

Could you please send us a sample code/ pseudo code if possible which depicts the problem statement that you are trying to solve.

 

Thanks & Regards

Goutham

View solution in original post

0 Kudos
5 Replies
GouthamK_Intel
Moderator
1,595 Views

Hi,

Thanks for reaching out to us!

My understanding of the cl::sycl::context is that they are used among the different devices on a system. For example, I can only access memory allocated on a given cl::sycl::device using a cl::sycl::queue that was instantiated with the cl::sycl::context associated to said device, i.e. using cl::sycl::device::get_context().

When you create multiple queues even with the same device, multiple contexts get created. As they are two different SYCL contexts and any buffer you create will be a part of that context.

Could you please send us a sample code/ pseudo code if possible which depicts the problem statement that you are trying to solve.

 

Thanks & Regards

Goutham

0 Kudos
GouthamK_Intel
Moderator
1,562 Views

Hi,

Could you please confirm if your issue is resolved?

If not, provide us a sample code/ pseudo code that depicts the problem statement that you are trying to solve?


Regards

Goutham


0 Kudos
Pascuzzi__Vincent
1,556 Views

Yes -- thanks. (I thought that was implied after selecting your post as the solution.)

0 Kudos
GouthamK_Intel
Moderator
1,545 Views

Hi,

Thanks for the confirmation!

As this issue has been resolved, we will no longer respond to this thread. 

If you require any additional assistance from Intel, please start a new thread. 

Any further interaction in this thread will be considered community only.


Thanks & Regards

Goutham


0 Kudos
Gregg_S_Intel
Employee
257 Views

A SYCL context contains a collection of devices that the host can use and manages memory objects that can be shared between the devices.

Multiple devices on same platform can share a context, and multiple queues can share same context.

SYCL USM data is accessible on other devices in same context.

 

auto P = sycl::platform p(sycl::gpu_seclector_v);
auto devices = P.get_devices();
auto C = sycl::context(devices);
sycl::queue q0 = new sycl::queue(C, devices[0]);
sycl::queue q1 = new sycl::queue(C, devices[1]);
a = sycl::malloc_device<float>(N, q0);
b = sycl::malloc_device<float>(N, q1);
q0.memcpy(a, host_a, sizeof(float) * N).wait();
q1.memcpy(b, host_b, sizeof(float) * N).wait();
q0.parallel_for(sycl::range{N}, [=](sycl::item<1> i) {
a[i] += b[i]; // buffer b on device 1 is added to buffer a on device 0
});
0 Kudos
Reply