-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathClCommandQueue.h
59 lines (46 loc) · 1.44 KB
/
ClCommandQueue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* ClCommandQueue.h
*
* Created on: Feb 1, 2021
* Author: tugrul
*/
#ifndef CLCOMMANDQUEUE_H_
#define CLCOMMANDQUEUE_H_
#include<iostream>
#include<memory>
#include"ClContext.h"
#include"ClDevice.h"
#include<CL/cl.h>
#include<stdexcept>
// wrapper for opencl command queue for simple usage in opencl operations
// default property is chosen when property parameter is null and this means in-order execution of opencl commands on same command queue
// smart pointer is taking care of releasing its resources but be cautious for scope. Every higher level object needs to stay alive until lower levels are freed
class ClCommandQueue
{
public:
ClCommandQueue(){ q=nullptr;}
ClCommandQueue(ClContext ctx, ClDevice dev)
{
q=std::shared_ptr<cl_command_queue>(new cl_command_queue(),[](cl_command_queue * ptr){ if(CL_SUCCESS!=clReleaseCommandQueue(*ptr)){std::cout<<"error: release queue"<<std::endl;} delete ptr;});
cl_int err;
cl_queue_properties prop[3] = {CL_QUEUE_PROPERTIES , CL_QUEUE_PROFILING_ENABLE, 0};
*q = clCreateCommandQueueWithProperties(*ctx.ctxPtr(), *dev.devPtr(), 0, &err);
/*
*q=clCreateCommandQueue(
*ctx.ctxPtr(),
*dev.devPtr(),
0,
&err
);
*/
if(CL_SUCCESS!=err)
{
throw std::invalid_argument("error: command queue");
}
}
cl_command_queue getQueue() const noexcept { return *q;}
~ClCommandQueue(){}
private:
std::shared_ptr<cl_command_queue> q;
};
#endif /* CLCOMMANDQUEUE_H_ */