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

How to understand this `handler`

Klen
Beginner
684 Views

We can use both `buffers` and `USM` implementations in `oneapi`,
In `USM`:

queue q;
int *data1 = malloc_shared<int>(128, q);
for (int i = 0; i < N; i++) {
data1[i] = 10;
}
auto e1 = q.parallel_for(range<1>(N), [=](id<1> i) { data1[i] += 2; });

We use `q.parallel_for` to do parallel computing.

In `buffers`

std::vector<int> vector1(128, 10);
buffer vector1_buffer(vector1);
queue q;
q.submit([&](handler &h) {
    accessor vector1_accessor (vector1_buffer,h);
    h.parallel_for(range<1>(N), [=](id<1> index) {
        vector1_accessor[index] += 1;
    });
});


We pass `handler` to the lambda function and use `h.parallel_for` to do parallel computing.

My question is what is handler, how do I understand it? What is the different between `handler` and `queue`?

0 Kudos
1 Solution
VaishnaviV_Intel
Moderator
633 Views

Hi,

 

Thank you for posting in Intel communities. 

 

>>what is handler, how do I understand it? What is the different between `handler` and `queue`?

 

A command group usually contains code, that defines dependences running as part of the host program (so that the runtime knows what the dependences are) and device code running in the future once the dependences are satisfied. 

A command group handler gives more control over how code is submitted to the queue.

 

A DPC++ queue is employed to schedule and execute the command queues on the devices.

Queue also uses a shortcut method that directly invoke parallel_for on the queue object instead of inside a lambda passed to the submit method (a command group).

 

 

Queues are used to schedule the execution of a set of handlers, ensuring that dependencies between commands are correctly managed. 

The handler encapsulates the details of a single parallel computation, while the queue manages the execution of a set of handlers.

 

Please refer to the Data parallel C++ Textbook by James Reinders for more details.

 

Thanks & Regards,

Vankudothu Vaishnavi.

 

View solution in original post

0 Kudos
3 Replies
VaishnaviV_Intel
Moderator
634 Views

Hi,

 

Thank you for posting in Intel communities. 

 

>>what is handler, how do I understand it? What is the different between `handler` and `queue`?

 

A command group usually contains code, that defines dependences running as part of the host program (so that the runtime knows what the dependences are) and device code running in the future once the dependences are satisfied. 

A command group handler gives more control over how code is submitted to the queue.

 

A DPC++ queue is employed to schedule and execute the command queues on the devices.

Queue also uses a shortcut method that directly invoke parallel_for on the queue object instead of inside a lambda passed to the submit method (a command group).

 

 

Queues are used to schedule the execution of a set of handlers, ensuring that dependencies between commands are correctly managed. 

The handler encapsulates the details of a single parallel computation, while the queue manages the execution of a set of handlers.

 

Please refer to the Data parallel C++ Textbook by James Reinders for more details.

 

Thanks & Regards,

Vankudothu Vaishnavi.

 

0 Kudos
VaishnaviV_Intel
Moderator
575 Views

Hi,

 

Has the information provided above helped? If yes, could you please confirm whether we can close this thread from our end?


Thanks and Regards,

Vankudothu Vaishnavi.


0 Kudos
VaishnaviV_Intel
Moderator
485 Views

Hi,


We assume that your issue is resolved. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.


Thanks & Regards,

Vankudothu Vaishnavi.


0 Kudos
Reply