|
17 | 17 | //
|
18 | 18 | // Example usage:
|
19 | 19 | //
|
20 |
| -// auto Info = new AllocDeleterCallbackInfo(USMFreeFuncPtr, Context, |
| 20 | +// auto Info = new AllocDeleterCallbackInfoUSM(USMFreeFuncPtr, Context, |
21 | 21 | // Allocation); clSetEventCallback(USMOpEvent, CL_COMPLETE,
|
22 | 22 | // AllocDeleterCallback, Info);
|
23 |
| -struct AllocDeleterCallbackInfo { |
24 |
| - AllocDeleterCallbackInfo(clMemBlockingFreeINTEL_fn USMFree, |
25 |
| - cl_context CLContext, void *Allocation) |
26 |
| - : USMFree(USMFree), CLContext(CLContext), Allocation(Allocation) { |
| 23 | + |
| 24 | +struct AllocDeleterCallbackInfoBase { |
| 25 | + AllocDeleterCallbackInfoBase(cl_context Context, uint8_t *Allocation) |
| 26 | + : CLContext(Context), Allocation(Allocation) { |
27 | 27 | clRetainContext(CLContext);
|
28 | 28 | }
|
29 |
| - ~AllocDeleterCallbackInfo() { |
30 |
| - USMFree(CLContext, Allocation); |
31 |
| - clReleaseContext(CLContext); |
32 |
| - } |
33 |
| - AllocDeleterCallbackInfo(const AllocDeleterCallbackInfo &) = delete; |
34 |
| - AllocDeleterCallbackInfo & |
35 |
| - operator=(const AllocDeleterCallbackInfo &) = delete; |
36 | 29 |
|
37 |
| - clMemBlockingFreeINTEL_fn USMFree; |
| 30 | + virtual ~AllocDeleterCallbackInfoBase() { clReleaseContext(CLContext); } |
| 31 | + |
| 32 | + AllocDeleterCallbackInfoBase(const AllocDeleterCallbackInfoBase &) = delete; |
| 33 | + AllocDeleterCallbackInfoBase & |
| 34 | + operator=(const AllocDeleterCallbackInfoBase &) = delete; |
| 35 | + |
| 36 | +protected: |
38 | 37 | cl_context CLContext;
|
39 |
| - void *Allocation; |
| 38 | + uint8_t *Allocation; |
40 | 39 | };
|
41 | 40 |
|
42 |
| -struct AllocDeleterCallbackInfoWithQueue : AllocDeleterCallbackInfo { |
43 |
| - AllocDeleterCallbackInfoWithQueue(clMemBlockingFreeINTEL_fn USMFree, |
44 |
| - cl_context CLContext, void *Allocation, |
45 |
| - cl_command_queue CLQueue) |
46 |
| - : AllocDeleterCallbackInfo(USMFree, CLContext, Allocation), |
47 |
| - CLQueue(CLQueue) { |
48 |
| - clRetainContext(CLContext); |
| 41 | +struct AllocDeleterCallbackInfo : AllocDeleterCallbackInfoBase { |
| 42 | + AllocDeleterCallbackInfo(cl_context CLContext, uint8_t *Allocation) |
| 43 | + : AllocDeleterCallbackInfoBase(CLContext, Allocation) {} |
| 44 | + |
| 45 | + ~AllocDeleterCallbackInfo() override { delete[] Allocation; } |
| 46 | +}; |
| 47 | + |
| 48 | +struct AllocDeleterCallbackInfoUSM : AllocDeleterCallbackInfoBase { |
| 49 | + AllocDeleterCallbackInfoUSM(clMemBlockingFreeINTEL_fn USMFree, |
| 50 | + cl_context CLContext, uint8_t *Allocation) |
| 51 | + : AllocDeleterCallbackInfoBase(CLContext, Allocation), USMFree(USMFree) {} |
| 52 | + ~AllocDeleterCallbackInfoUSM() override { USMFree(CLContext, Allocation); } |
| 53 | + |
| 54 | + clMemBlockingFreeINTEL_fn USMFree; |
| 55 | +}; |
| 56 | + |
| 57 | +struct AllocDeleterCallbackInfoUSMWithQueue : AllocDeleterCallbackInfoUSM { |
| 58 | + AllocDeleterCallbackInfoUSMWithQueue(clMemBlockingFreeINTEL_fn USMFree, |
| 59 | + cl_context CLContext, |
| 60 | + uint8_t *Allocation, |
| 61 | + cl_command_queue CLQueue) |
| 62 | + : AllocDeleterCallbackInfoUSM(USMFree, CLContext, Allocation), |
| 63 | + CLQueue(CLQueue) {} |
| 64 | + ~AllocDeleterCallbackInfoUSMWithQueue() override { |
| 65 | + clReleaseCommandQueue(CLQueue); |
49 | 66 | }
|
50 |
| - ~AllocDeleterCallbackInfoWithQueue() { clReleaseCommandQueue(CLQueue); } |
51 |
| - AllocDeleterCallbackInfoWithQueue(const AllocDeleterCallbackInfoWithQueue &) = |
52 |
| - delete; |
53 |
| - AllocDeleterCallbackInfoWithQueue & |
54 |
| - operator=(const AllocDeleterCallbackInfoWithQueue &) = delete; |
55 | 67 |
|
56 | 68 | cl_command_queue CLQueue;
|
57 | 69 | };
|
58 | 70 |
|
59 | 71 | template <class T>
|
60 |
| -void AllocDeleterCallback(cl_event event, cl_int, void *pUserData); |
| 72 | +void AllocDeleterCallback(cl_event event, cl_int, uint8_t *pUserData); |
0 commit comments