本文整理汇总了C#中Kernel.GetWorkGroupSize方法的典型用法代码示例。如果您正苦于以下问题:C# Kernel.GetWorkGroupSize方法的具体用法?C# Kernel.GetWorkGroupSize怎么用?C# Kernel.GetWorkGroupSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kernel
的用法示例。
在下文中一共展示了Kernel.GetWorkGroupSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteKernel
private unsafe void ExecuteKernel(
Context context,
Device device,
CommandQueue commandQueue,
Kernel kernel,
float[] input,
float[] output,
int globalWorkSize,
int localWorkSize,
bool warming,
bool useHostPointer,
bool autoGroupSize,
bool enableProfiling,
out TimeSpan stopwatchTime,
out TimeSpan profiledTime,
out TimeSpan readTime)
{
MemoryFlags inFlags = (useHostPointer ? MemoryFlags.UseHostPointer : MemoryFlags.CopyHostPointer) | MemoryFlags.ReadOnly;
MemoryFlags outFlags = (useHostPointer ? MemoryFlags.UseHostPointer : MemoryFlags.CopyHostPointer) | MemoryFlags.ReadWrite;
int taskSize = input.Length;
// allocate buffers
fixed (float* pinput = input, poutput = output)
{
using (Buffer inputBuffer = context.CreateBuffer(inFlags, sizeof(float) * taskSize, (IntPtr)pinput),
outputBuffer = context.CreateBuffer(outFlags, sizeof(float) * taskSize, (IntPtr)poutput))
{
kernel.Arguments[0].SetValue(inputBuffer);
kernel.Arguments[1].SetValue(outputBuffer);
Console.WriteLine("Original global work size {0}", globalWorkSize);
Console.WriteLine("Original local work size {0}", localWorkSize);
if (autoGroupSize)
{
Console.WriteLine("Run-time determines optimal workgroup size");
}
IntPtr workGroupSizeMaximum = kernel.GetWorkGroupSize(device);
Console.WriteLine("Maximum workgroup size for this kernel {0}", workGroupSizeMaximum.ToInt64());
if (warming)
{
Console.Write("Warming up OpenCL execution...");
using (commandQueue.EnqueueNDRangeKernel(kernel, new[] { (IntPtr)globalWorkSize }, autoGroupSize ? null : new[] { (IntPtr)localWorkSize }))
{
}
commandQueue.Finish();
Console.WriteLine("Done");
}
Console.Write("Executing OpenCL kernel...");
Stopwatch timer = Stopwatch.StartNew();
// execute kernel, pls notice autoGroupSize
using (Event perfEvent = commandQueue.EnqueueNDRangeKernel(kernel, new[] { (IntPtr)globalWorkSize }, autoGroupSize ? null : new[] { (IntPtr)localWorkSize }))
{
Event.WaitAll(perfEvent);
stopwatchTime = timer.Elapsed;
Console.WriteLine("Done");
if (enableProfiling)
{
ulong start = perfEvent.CommandStartTime;
ulong end = perfEvent.CommandEndTime;
// a tick is 100ns
profiledTime = TimeSpan.FromTicks((long)(end - start) / 100);
}
else
{
profiledTime = TimeSpan.Zero;
}
}
timer.Restart();
if (useHostPointer)
{
IntPtr tmpPtr;
using (commandQueue.EnqueueMapBuffer(outputBuffer, true, MapFlags.Read, 0, sizeof(float) * taskSize, out tmpPtr))
{
}
Assert.AreEqual((IntPtr)poutput, tmpPtr, "EnqueueMapBuffer failed to return original pointer");
using (commandQueue.EnqueueUnmapMemObject(outputBuffer, tmpPtr))
{
}
}
else
{
using (commandQueue.EnqueueReadBuffer(outputBuffer, true, 0, sizeof(float) * taskSize, (IntPtr)poutput))
{
}
}
commandQueue.Finish();
readTime = timer.Elapsed;
}
//.........这里部分代码省略.........