本文整理汇总了C#中ComputeCommandQueue类的典型用法代码示例。如果您正苦于以下问题:C# ComputeCommandQueue类的具体用法?C# ComputeCommandQueue怎么用?C# ComputeCommandQueue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ComputeCommandQueue类属于命名空间,在下文中一共展示了ComputeCommandQueue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MaterialCache
public MaterialCache(ComputeCommandQueue commandQueue)
{
_commandQueue = commandQueue;
_materialArray = new Material[DefaultCacheSize];
Buffer = new ComputeBuffer<Material>(commandQueue.Context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.UseHostPointer, _materialArray);
}
示例2: RunInternal
protected override void RunInternal()
{
ComputeCommandQueue commands = new ComputeCommandQueue(context, context.Devices[0], ComputeCommandQueueFlags.Profiling);
Console.WriteLine("Original content:");
Random rand = new Random();
int count = 6;
long[] bufferContent = new long[count];
for (int i = 0; i < count; i++)
{
bufferContent[i] = (long)(rand.NextDouble() * long.MaxValue);
Console.WriteLine("\t" + bufferContent[i]);
}
ComputeBuffer<long> buffer = new ComputeBuffer<long>(context, ComputeMemoryFlags.CopyHostPointer, bufferContent);
IntPtr mappedPtr = commands.Map(buffer, false, ComputeMemoryMappingFlags.Read, 0, bufferContent.Length, null);
commands.Finish();
Console.WriteLine("Mapped content:");
for (int i = 0; i < bufferContent.Length; i++)
{
IntPtr ptr = new IntPtr(mappedPtr.ToInt64() + i * sizeof(long));
Console.WriteLine("\t" + Marshal.ReadInt64(ptr));
}
commands.Unmap(buffer, ref mappedPtr, null);
}
示例3: OpenCLProxy
public OpenCLProxy(bool useSoftware = false)
{
HardwareAccelerationEnabled = ComputePlatform.Platforms.Count != 0 && !useSoftware;
if (HardwareAccelerationEnabled)
{
ComputePlatform platform = ComputePlatform.Platforms[0];
var devices = new List<ComputeDevice> { platform.Devices[0] };
var properties = new ComputeContextPropertyList(platform);
_context = new ComputeContext(devices, properties, null, IntPtr.Zero);
_commands = new ComputeCommandQueue(_context, _context.Devices[0], ComputeCommandQueueFlags.None);
_intComputeBuffers = new Dictionary<string, ComputeBuffer<int>>();
_floatComputeBuffers = new Dictionary<string, ComputeBuffer<float>>();
AcceleratorName = platform.Name;
}
else
{
AcceleratorName = "CPU";
}
_intArguments = new Dictionary<string, int>();
_intBuffers = new Dictionary<string, int[]>();
_floatArguments = new Dictionary<string, float>();
_floatBuffers = new Dictionary<string, float[]>();
_doubleArguments = new Dictionary<string, double>();
}
示例4: OpenCLQueue
internal OpenCLQueue(OpenCLContext context, ComputeCommandQueue computeCommandQueue)
{
Contract.Requires(context != null);
Contract.Requires(computeCommandQueue != null);
Context = context;
ComputeCommandQueue = computeCommandQueue;
}
示例5: GpuBvhTree
public GpuBvhTree(ComputeCommandQueue commandQueue,
List<Triangle> prims, List<SimplePointLight> lights, int maxPrimsPerNode)
: base(prims, maxPrimsPerNode)
{
_commandQueue = commandQueue;
_lights = lights;
initBuffers();
}
示例6: ComputeEvent
internal ComputeEvent(IntPtr handle, ComputeCommandQueue queue)
{
unsafe
{
Handle = handle;
commandQueue = queue;
commandType = (ComputeCommandType)GetInfo<ComputeEventInfo, uint>(
ComputeEventInfo.CommandType, CL10.GetEventInfo);
}
}
示例7: ComputeEvent
internal ComputeEvent(CLEventHandle handle, ComputeCommandQueue queue)
{
Handle = handle;
SetID(Handle.Value);
CommandQueue = queue;
Type = (ComputeCommandType)GetInfo<CLEventHandle, ComputeEventInfo, int>(Handle, ComputeEventInfo.CommandType, CLInterface.CL10.GetEventInfo);
Context = queue.Context;
if (ComputeTools.ParseVersionString(CommandQueue.Device.Platform.Version, 1) > new Version(1, 0))
HookNotifier();
}
示例8: ComputeEvent
internal ComputeEvent(CLEventHandle handle, ComputeCommandQueue queue)
{
Handle = handle;
SetID(Handle.Value);
CommandQueue = queue;
Type = (ComputeCommandType)GetInfo<CLEventHandle, ComputeEventInfo, int>(Handle, ComputeEventInfo.CommandType, CL10.GetEventInfo);
Context = queue.Context;
if (ComputeTools.ParseVersionString(CommandQueue.Device.Platform.Version, 1) > new Version(1, 0))
HookNotifier();
Trace.WriteLine("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
}
示例9: Run
public static void Run(TextWriter log, ComputeContext context)
{
StartTest(log, "Image test");
try
{
log.Write("Creating command queue... ");
ComputeCommandQueue commands = new ComputeCommandQueue(context, context.Devices[0], ComputeCommandQueueFlags.None);
log.WriteLine("done.");
int width = 16;
int height = 16;
log.Write("Creating first bitmap and drawing shapes... ");
Bitmap firstBitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
Graphics graphics = Graphics.FromImage(firstBitmap);
graphics.FillEllipse(Brushes.Red, 0, 0, width / 2, height / 2);
graphics.FillRectangle(Brushes.Green, width / 2 + 1, 0, width / 2, height / 2);
graphics.FillRectangle(Brushes.Blue, width / 2 + 1, height / 2 + 1, width / 2, height / 2);
log.WriteLine("done.");
log.Write("Creating OpenCL image object from first bitmap... ");
ComputeImage2D clImage = new ComputeImage2D(context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, firstBitmap);
log.WriteLine("done.");
log.Write("Creating second bitmap... ");
Bitmap secondBitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
BitmapData bmpData = secondBitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, secondBitmap.PixelFormat);
log.WriteLine("done.");
log.Write("Reading from OpenCL image object... ");
commands.ReadFromImage(clImage, bmpData.Scan0, true, null);
log.WriteLine("done.");
secondBitmap.UnlockBits(bmpData);
log.Write("Comparing bitmaps... ");
for (int i = 0; i < width; i++)
for (int j = 0; j < height; j++)
if (firstBitmap.GetPixel(i, j) != secondBitmap.GetPixel(i, j))
throw new Exception("Image data mismatch!");
log.WriteLine("passed.");
}
catch (Exception e)
{
log.WriteLine(e.ToString());
}
EndTest(log, "Image test");
}
示例10: ComputeEvent
internal ComputeEvent(IntPtr handle, ComputeCommandQueue queue)
{
unsafe
{
Handle = handle;
CommandQueue = queue;
Type = (ComputeCommandType)GetInfo<ComputeEventInfo, uint>(
ComputeEventInfo.CommandType, CL10.GetEventInfo);
Context = queue.Context;
if (CommandQueue.Device.Version == new Version(1, 1))
HookNotifier();
Completed += new ComputeCommandStatusChanged(ComputeEvent_Fired);
Aborted += new ComputeCommandStatusChanged(ComputeEvent_Fired);
}
}
示例11: SetupDevice
public void SetupDevice(params string[] kernelNames) {
try {
this.program.Build(new[] { device }, string.Empty, null, IntPtr.Zero);
}
catch (Exception) {
Tracer.TraceLine(this.program.GetBuildLog(ComputePlatform.Platforms[0].Devices[0]));
throw;
}
if (kernelNames.Length > 1)
{
kernels = program.CreateAllKernels().ToDictionary(item => item.FunctionName);
}
else
{
kernel = program.CreateKernel(kernelNames[0]);
}
commands = new ComputeCommandQueue(context, context.Devices[0], ComputeCommandQueueFlags.None);
}
示例12: ConductSearch
private static void ConductSearch(ComputeContext context, ComputeKernel kernel)
{
var todos = GetQueenTaskPartition(NumQueens, 4);
var done = new List<QueenTask>();
ComputeEventList eventList = new ComputeEventList();
var commands = new ComputeCommandQueue(context, context.Devices[1], ComputeCommandQueueFlags.None);
Console.WriteLine("Starting {0} tasks, and working {1} at a time.", todos.Count, Spread);
QueenTask[] inProgress = GetNextAssignment(new QueenTask[] {}, todos, done);
var sw = new Stopwatch();
sw.Start();
while (inProgress.Any())
{
var taskBuffer =
new ComputeBuffer<QueenTask>(context,
ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer,
inProgress);
kernel.SetMemoryArgument(0, taskBuffer);
commands.WriteToBuffer(inProgress, taskBuffer, false, null);
for (int i = 0; i < 12; i++)
commands.Execute(kernel, null, new long[] { inProgress.Length }, null, eventList);
commands.ReadFromBuffer(taskBuffer, ref inProgress, false, eventList);
commands.Finish();
inProgress = GetNextAssignment(inProgress, todos, done);
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds / 1000.0);
ulong sum = done.Select(state => state.solutions)
.Aggregate((total, next) => total + next);
Console.WriteLine("Q({0})={1}", NumQueens, sum);
}
示例13: Run
public void Run(ComputeContext context, TextWriter log)
{
try
{
ComputeCommandQueue commands = new ComputeCommandQueue(context, context.Devices[0], ComputeCommandQueueFlags.None);
log.WriteLine("Original content:");
Random rand = new Random();
int count = 6;
long[] bufferContent = new long[count];
for (int i = 0; i < count; i++)
{
bufferContent[i] = (long)(rand.NextDouble() * long.MaxValue);
log.WriteLine("\t" + bufferContent[i]);
}
ComputeBuffer<long> buffer = new ComputeBuffer<long>(context, ComputeMemoryFlags.CopyHostPointer, bufferContent);
IntPtr mappedPtr = commands.Map(buffer, true, ComputeMemoryMappingFlags.Read, 0, bufferContent.Length, null);
log.WriteLine("Mapped content:");
for (int i = 0; i < bufferContent.Length; i++)
{
IntPtr ptr = new IntPtr(mappedPtr.ToInt64() + i * sizeof(long));
log.WriteLine("\t" + Marshal.ReadInt64(ptr));
}
commands.Unmap(buffer, ref mappedPtr, null);
// wait for the unmap to happen
commands.Finish();
// cleanup buffer
buffer.Dispose();
// cleanup commands
commands.Dispose();
}
catch (Exception e)
{
log.WriteLine(e.ToString());
}
}
示例14: ComputeEvent
internal ComputeEvent(IntPtr handle, ComputeCommandQueue queue)
{
unsafe
{
Handle = handle;
CommandQueue = queue;
Type = (ComputeCommandType)GetInfo<ComputeEventInfo, uint>(
ComputeEventInfo.CommandType, CL10.GetEventInfo);
Context = queue.Context;
if (CommandQueue.Device.Version == new Version(1, 1))
HookNotifier();
Completed += new ComputeCommandStatusChanged(ComputeEvent_Fired);
Aborted += new ComputeCommandStatusChanged(ComputeEvent_Fired);
}
Trace.WriteLine("Created " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").");
}
示例15: Run
public static void Run(TextWriter log, ComputeContext context)
{
StartTest(log, "Dummy test");
try
{
ComputeCommandQueue commands = new ComputeCommandQueue(context, context.Devices[0], ComputeCommandQueueFlags.None);
log.WriteLine("Original content:");
Random rand = new Random();
int count = 6;
long[] bufferContent = new long[count];
for (int i = 0; i < count; i++)
{
bufferContent[i] = (long)(rand.NextDouble() * long.MaxValue);
log.WriteLine("\t" + bufferContent[i]);
}
ComputeBuffer<long> buffer = new ComputeBuffer<long>(context, ComputeMemoryFlags.CopyHostPointer, bufferContent);
IntPtr mappedPtr = commands.Map(buffer, false, ComputeMemoryMappingFlags.Read, 0, bufferContent.Length, null);
commands.Finish();
log.WriteLine("Mapped content:");
for (int i = 0; i < bufferContent.Length; i++)
{
IntPtr ptr = new IntPtr(mappedPtr.ToInt64() + i * sizeof(long));
log.WriteLine("\t" + Marshal.ReadInt64(ptr));
}
commands.Unmap(buffer, ref mappedPtr, null);
}
catch (Exception e)
{
log.WriteLine(e.ToString());
}
EndTest(log, "Dummy test");
}