-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathEvent.cs
131 lines (113 loc) · 3.83 KB
/
Event.cs
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
namespace OpenCl
{
using System;
using System.Runtime.InteropServices;
public enum ExecutionStatus : int
{
Complete = 0x0,
Running = 0x1,
Submitted = 0x2,
Queued = 0x3,
}
public enum CommandType : uint
{
NDRangeKernel = 0x11F0,
Task = 0x11F1,
NativeKernel = 0x11F2,
ReadBuffer = 0x11F3,
WriteBuffer = 0x11F4,
CopyBuffer = 0x11F5,
ReadImage = 0x11F6,
WriteImage = 0x11F7,
CopyImage = 0x11F8,
CopyImageToBuffer = 0x11F9,
CopyBufferToImage = 0x11FA,
MapBuffer = 0x11FB,
MapImage = 0x11FC,
UnmapMemObject = 0x11FD,
Marker = 0x11FE,
AcquireGlObjects = 0x11FF,
ReleaseGlObjects = 0x1200,
ReadBufferRect = 0x1201,
WriteBufferRect = 0x1202,
CopyBufferRect = 0x1203,
User = 0x1204,
Barrier = 0x1205,
MigrateMemObjects = 0x1206,
FillBuffer = 0x1207,
FillImage = 0x1208,
SvmFree = 0x1209,
SvmMemcpy = 0x120A,
SvmMemfill = 0x120B,
SvmMap = 0x120C,
SvmUnmap = 0x120D,
}
public sealed class Event : RefCountedObject
{
private const uint CL_EVENT_COMMAND_QUEUE = 0x11D0;
private const uint CL_EVENT_COMMAND_TYPE = 0x11D1;
private const uint CL_EVENT_REFERENCE_COUNT = 0x11D2;
private const uint CL_EVENT_COMMAND_EXECUTION_STATUS = 0x11D3;
private const uint CL_EVENT_CONTEXT = 0x11D4;
internal Event(IntPtr handle) : base(handle) { }
// Event attributes
public CommandQueue CommandQueue
{
get {
var queue = Cl.GetInfo<IntPtr>(NativeMethods.clGetEventInfo, this.handle, CL_EVENT_COMMAND_QUEUE);
return new CommandQueue(queue);
}
}
public CommandType CommandType
{
get { return Cl.GetInfoEnum<CommandType>(NativeMethods.clGetEventInfo, this.handle, CL_EVENT_COMMAND_TYPE); }
}
public uint ReferenceCount
{
get { return Cl.GetInfo<uint>(NativeMethods.clGetEventInfo, this.handle, CL_EVENT_REFERENCE_COUNT); }
}
public ExecutionStatus ExecutionStatus
{
get { return Cl.GetInfoEnum<ExecutionStatus>(NativeMethods.clGetEventInfo, this.handle, CL_EVENT_COMMAND_EXECUTION_STATUS); }
}
public Context Context
{
get {
var ctx = Cl.GetInfo<IntPtr>(NativeMethods.clGetEventInfo, this.handle, CL_EVENT_CONTEXT);
return new Context(ctx);
}
}
// Event methods
public static void WaitForEvents(Event[] eventWaitList)
{
var l = ToIntPtr(eventWaitList);
NativeMethods.clWaitForEvents((uint)l.Length, l);
}
// RefCountedObject
protected override void Retain()
{
NativeMethods.clRetainEvent(this.handle);
}
protected override void Release()
{
NativeMethods.clReleaseEvent(this.handle);
}
// utilities
internal static Event[] FromIntPtr(IntPtr[] arr)
{
var res = new Event[arr.Length];
for (var i=0; i<res.Length; i++) {
res[i] = new Event(arr[i]);
}
return res;
}
internal static IntPtr[] ToIntPtr(Event[] events)
{
var res = new IntPtr[events.Length];
for (var i=0; i<events.Length; i++) {
res[i] = events[i].handle;
}
return res;
}
}
}