Debian Codegraph @

cmrtlib/agnostic/hardware/cm_queue.h

raw
1 /*
2 * Copyright (c) 2017, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 #ifndef CMRTLIB_AGNOSTIC_HARDWARE_CM_QUEUE_H_
23 #define CMRTLIB_AGNOSTIC_HARDWARE_CM_QUEUE_H_
24
25 #include "cm_queue_base_hw.h"
26 #include "cm_def_os.h"
27
28 class CmEvent;
29 class CmSurface2D;
30 class CmDevice_RT;
31 class CmThreadSpace;
32 class CmTask;
33 class CmThreadGroupSpace;
34
35 typedef enum _CM_FASTCOPY_DIRECTION
36 {
37 CM_FASTCOPY_GPU2CPU = 0,
38 CM_FASTCOPY_CPU2GPU = 1
39 } CM_FASTCOPY_DIRECTION;
40
41 typedef enum _CM_FASTCOPY_OPTION
42 {
43 CM_FASTCOPY_OPTION_NONBLOCKING = 0x00,
44 CM_FASTCOPY_OPTION_BLOCKING = 0x01
45 } CM_FASTCOPY_OPTION;
46
47 //CM_ENQUEUE_GPUCOPY_PARAM version 2: two new fields are added
48 typedef struct _CM_ENQUEUE_GPUCOPY_PARAM
49 {
50 void *cmQueueHandle; // [in] CmQueue pointer in CMRT@UMD
51
52 void *cmSurface2d; // [in] CmSurface2d pointer in CMRT@UMD
53
54 void *sysMem; // [in] pointer of system memory
55
56 CM_FASTCOPY_DIRECTION copyDir; // [in] direction for GPUCopy: CM_FASTCOPY_GPU2CPU (0) or CM_FASTCOPY_CPU2GPU(1)
57
58 uint32_t widthStride; // [in] width stride in byte for system memory, ZERO means no setting
59
60 uint32_t heightStride; // [in] height stride in row for system memory, ZERO means no setting
61
62 uint32_t option; // [in] option passed by user, only support CM_FASTCOPY_OPTION_NONBLOCKING(0) and CM_FASTCOPY_OPTION_BLOCKING(1)
63
64 void *cmEventHandle; // [in/out] return CmDevice pointer in CMRT@UMD, nullptr if the input is CM_NO_EVENT
65
66 uint32_t eventIndex; // [out] index of Event in m_EventArray
67
68 int32_t returnValue; // [out] return value from CMRT@UMD
69 } CM_ENQUEUE_GPUCOPY_PARAM, *PCM_ENQUEUE_GPUCOPY_PARAM;
70
71 class CmQueue_RT : public CmQueue
72 {
73 public:
74 static int32_t Create(CmDevice_RT *device,
75 CmQueue_RT* &queue,
76 CM_QUEUE_CREATE_OPTION queueCreateOption);
77 static int32_t Destroy(CmQueue_RT *&queue);
78
79 CM_RT_API int32_t Enqueue(CmTask *task,
80 CmEvent *&event,
81 const CmThreadSpace *threadSpace = nullptr);
82
83 CM_RT_API int32_t EnqueueCopyCPUToGPU(CmSurface2D *surface,
84 const unsigned char *sysMem,
85 CmEvent *&event);
86
87 CM_RT_API int32_t EnqueueCopyGPUToCPU(CmSurface2D *surface,
88 unsigned char *sysMem,
89 CmEvent *&event);
90
91 CM_RT_API int32_t EnqueueInitSurface2D(CmSurface2D *surface,
92 const uint32_t initValue,
93 CmEvent *&event);
94
95 CM_RT_API int32_t EnqueueCopyGPUToGPU(CmSurface2D *outputSurface,
96 CmSurface2D *inputSurface,
97 uint32_t option,
98 CmEvent *&event);
99
100 CM_RT_API int32_t EnqueueCopyCPUToCPU(unsigned char *dstSysMem,
101 unsigned char *srcSysMem,
102 uint32_t size,
103 uint32_t option,
104 CmEvent *&event);
105
106 CM_RT_API int32_t EnqueueCopyCPUToGPUFullStride(CmSurface2D *surface,
107 const unsigned char *sysMem,
108 const uint32_t widthStride,
109 const uint32_t heightStride,
110 const uint32_t option,
111 CmEvent *&event);
112
113 CM_RT_API int32_t EnqueueCopyGPUToCPUFullStride(CmSurface2D *surface,
114 unsigned char *sysMem,
115 const uint32_t widthStride,
116 const uint32_t heightStride,
117 const uint32_t option,
118 CmEvent *&event);
119
120 CM_RT_API int32_t DestroyEvent(CmEvent *&event);
121
122 CM_RT_API int32_t
123 EnqueueWithGroup(CmTask *task,
124 CmEvent *&event,
125 const CmThreadGroupSpace *threadGroupSpace = nullptr);
126
127 CM_RT_API int32_t EnqueueCopyCPUToGPUFullStrideDup(CmSurface2D *surface,
128 const unsigned char *sysMem,
129 const uint32_t widthStride,
130 const uint32_t heightStride,
131 const uint32_t option,
132 CmEvent *&event);
133
134 CM_RT_API int32_t EnqueueCopyGPUToCPUFullStrideDup(CmSurface2D *surface,
135 unsigned char *sysMem,
136 const uint32_t widthStride,
137 const uint32_t heightStride,
138 const uint32_t option,
139 CmEvent *&event);
140
141 // enqueue CmBuffer read from GPU 1D surface to CPU system memory
142 CM_RT_API int32_t EnqueueReadBuffer(CmBuffer* buffer,
143 size_t offset,
144 const unsigned char* sysMem,
145 uint64_t sysMemSize,
146 CmEvent* wait_event,
147 CmEvent*& event,
148 unsigned option = 0);
149
150 // enqueue CmBuffer write from CPU system memory to GPU 1D surface
151 CM_RT_API int32_t EnqueueWriteBuffer(CmBuffer* buffer,
152 size_t offset,
153 const unsigned char* sysMem,
154 uint64_t sysMemSize,
155 CmEvent* wait_event,
156 CmEvent*& event,
157 unsigned option = 0);
158
159 CM_RT_API int32_t EnqueueWithHints(CmTask *task,
160 CmEvent *&event,
161 uint32_t hints = 0);
162
163 CM_RT_API int32_t EnqueueVebox(CmVebox *vebox, CmEvent *&event);
164
165 CM_RT_API int32_t EnqueueFast(CmTask *task,
166 CmEvent *&event,
167 const CmThreadSpace *threadSpace = nullptr);
168
169 CM_RT_API int32_t DestroyEventFast(CmEvent *&event);
170
171 CM_RT_API int32_t EnqueueWithGroupFast(CmTask *task,
172 CmEvent *&event,
173 const CmThreadGroupSpace *threadGroupSpace = nullptr);
174
175 CM_RT_API int32_t SetResidentGroupAndParallelThreadNum(uint32_t residentGroupNum, uint32_t parallelThreadNum);
176
177 CM_QUEUE_CREATE_OPTION GetQueueOption();
178
179
180 protected:
181 CmQueue_RT(CmDevice_RT *device, CM_QUEUE_CREATE_OPTION queueCreateOption);
182
183 ~CmQueue_RT();
184
185 int32_t Initialize();
186 int32_t Initialize(CM_QUEUE_CREATE_OPTION queueCreateOption);
187
188 int32_t EnqueueCopy(CmSurface2D *surface,
189 const unsigned char *sysMem,
190 const uint32_t widthStride,
191 const uint32_t heightStride,
192 CM_FASTCOPY_DIRECTION direction,
193 const uint32_t option,
194 CmEvent *&event);
195
196 CmDevice_RT *m_cmDev;
197
198 void *m_cmQueueHandle; //pointer used in driver
199
200 CM_QUEUE_CREATE_OPTION m_queueOption;
201
202 CSync m_criticalSection;
203
204 private:
205 CmQueue_RT(const CmQueue_RT &other);
206 CmQueue_RT &operator=(const CmQueue_RT &other);
207
208 };
209
210 #endif // #ifndef CMRTLIB_AGNOSTIC_HARDWARE_CM_QUEUE_H_