Intel® oneAPI DPC++/C++ Compiler
Talk to fellow users of Intel® oneAPI DPC++/C++ Compiler and companion tools like Intel® oneAPI DPC++ Library, Intel® DPC++ Compatibility Tool, and Intel® Distribution for GDB*

SYCL contexts and memory access

Pascuzzi__Vincent
Débutant
2 020 Visites

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 Compliments
1 Solution
GouthamK_Intel
Modérateur
2 003 Visites

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

Voir la solution dans l'envoi d'origine

0 Compliments
5 Réponses
GouthamK_Intel
Modérateur
2 004 Visites

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 Compliments
GouthamK_Intel
Modérateur
1 971 Visites

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 Compliments
Pascuzzi__Vincent
Débutant
1 965 Visites

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

0 Compliments
GouthamK_Intel
Modérateur
1 954 Visites

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 Compliments
Gregg_S_Intel
Employé
666 Visites

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 Compliments
Répondre