public void Dispose() { #if DEBUG Trace.WriteLine("Dispose " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information"); #endif CL10.ReleaseMemObject(handle); }
static ComputePlatform() { lock (typeof(ComputePlatform)) { try { if (platforms != null) { return; } IntPtr[] handles; int handlesLength; CL10.GetPlatformIDs(0, null, out handlesLength); handles = new IntPtr[handlesLength]; CL10.GetPlatformIDs(handlesLength, handles, out handlesLength); List <ComputePlatform> platformList = new List <ComputePlatform>(handlesLength); foreach (IntPtr handle in handles) { platformList.Add(new ComputePlatform(handle)); } platforms = platformList.AsReadOnly(); } catch (DllNotFoundException) { platforms = new List <ComputePlatform>().AsReadOnly(); } } }
public void Build(ICollection <ComputeDevice> devices, string options, ComputeProgramBuildNotifier notify, IntPtr notifyDataPtr) { IntPtr[] deviceHandles = ComputeTools.ExtractHandles(devices, out var handleCount); buildNotify = notify; CL10.BuildProgram(handle, handleCount, deviceHandles, options, buildNotify, notifyDataPtr); }
public ComputeProgram(ComputeContext context, string source) { handle = CL10.CreateProgramWithSource(context.handle, 1, new[] { source }, null, out _); #if DEBUG Trace.WriteLine("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information"); #endif }
internal ComputeKernel(string functionName, ComputeProgram program) { handle = CL10.CreateKernel(program.handle, functionName, out _); #if DEBUG Trace.WriteLine("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information"); #endif }
public ComputeContext(ICollection <ComputeDevice> devices, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr notifyDataPtr) { IntPtr[] deviceHandles = ComputeTools.ExtractHandles(devices, out var handleCount); IntPtr[] propertyArray = properties?.ToIntPtrArray(); handle = CL10.CreateContext(propertyArray, handleCount, deviceHandles, notify, notifyDataPtr, out _); #if DEBUG Trace.WriteLine("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information"); #endif }
public ComputeCommandQueue(ComputeContext context, ComputeDevice device, ComputeCommandQueueFlags properties) { handle = CL10.CreateCommandQueue(context.handle, device.handle, properties, out _); this.device = device; this.context = context; Events = new List <ComputeEvent>(); #if DEBUG Trace.WriteLine("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information"); #endif }
public ComputeBuffer(ComputeContext context, ComputeMemoryFlags flags, T[] data) { GCHandle dataPtr = GCHandle.Alloc(data, GCHandleType.Pinned); try { handle = CL10.CreateBuffer(context.handle, flags, new IntPtr(Unsafe.SizeOf <T>() * data.Length), dataPtr.AddrOfPinnedObject(), out _); } finally { dataPtr.Free(); } Init(); }
public void Read <T>(ComputeBuffer <T> source, bool blocking, long offset, long region, IntPtr destination, ICollection <ComputeEvent> events) where T : unmanaged { int eventWaitListSize; IntPtr[] eventHandles = ComputeTools.ExtractHandles(events, out eventWaitListSize); bool eventsWritable = events != null && !events.IsReadOnly; IntPtr[] newEventHandle = eventsWritable ? new IntPtr[1] : null; CL10.EnqueueReadBuffer(handle, source.handle, blocking, new IntPtr(offset * Unsafe.SizeOf <T>()), new IntPtr(region * Unsafe.SizeOf <T>()), destination, eventWaitListSize, eventHandles, newEventHandle); if (eventsWritable) { events.Add(new ComputeEvent(newEventHandle[0], this)); } }
public void Execute(ComputeKernel kernel, long[] globalWorkOffset, long[] globalWorkSize, long[] localWorkSize, ICollection <ComputeEvent> events) { int eventWaitListSize; IntPtr[] eventHandles = ComputeTools.ExtractHandles(events, out eventWaitListSize); bool eventsWritable = events != null && !events.IsReadOnly; IntPtr[] newEventHandle = eventsWritable ? new IntPtr[1] : null; CL10.EnqueueNDRangeKernel(handle, kernel.handle, globalWorkSize.Length, ComputeTools.ConvertArray(globalWorkOffset), ComputeTools.ConvertArray(globalWorkSize), ComputeTools.ConvertArray(localWorkSize), eventWaitListSize, eventHandles, newEventHandle); if (eventsWritable) { events.Add(new ComputeEvent(newEventHandle[0], this)); } }
public ReadOnlyCollection <ComputeDevice> QueryDevices() { int handlesLength = 0; CL10.GetDeviceIDs(handle, ComputeDeviceTypes.All, 0, null, out handlesLength); IntPtr[] handles = new IntPtr[handlesLength]; CL10.GetDeviceIDs(handle, ComputeDeviceTypes.All, handlesLength, handles, out handlesLength); ComputeDevice[] devices = new ComputeDevice[handlesLength]; for (int i = 0; i < handlesLength; i++) { devices[i] = new ComputeDevice(this, handles[i]); } this.devices = new ReadOnlyCollection <ComputeDevice>(devices); return(this.devices); }
public ComputeBuffer(ComputeContext context, ComputeMemoryFlags flags, long count, IntPtr dataPtr) { handle = CL10.CreateBuffer(context.handle, flags, new IntPtr(Unsafe.SizeOf <T>() * count), dataPtr, out _); Init(); }
public void SetArgument(int index, IntPtr dataSize, IntPtr dataAddr) { CL10.SetKernelArg(handle, index, dataSize, dataAddr); }
public void Finish() { CL10.Finish(handle); }