本文整理汇总了C#中ComputeCommandQueue.WriteToBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# ComputeCommandQueue.WriteToBuffer方法的具体用法?C# ComputeCommandQueue.WriteToBuffer怎么用?C# ComputeCommandQueue.WriteToBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ComputeCommandQueue
的用法示例。
在下文中一共展示了ComputeCommandQueue.WriteToBuffer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: TerrainGen
public TerrainGen()
{
#if CPU_DEBUG
var platform = ComputePlatform.Platforms[1];
#else
var platform = ComputePlatform.Platforms[0];
#endif
_devices = new List<ComputeDevice>();
_devices.Add(platform.Devices[0]);
_properties = new ComputeContextPropertyList(platform);
_context = new ComputeContext(_devices, _properties, null, IntPtr.Zero);
_cmdQueue = new ComputeCommandQueue(_context, _devices[0], ComputeCommandQueueFlags.None);
#region setup generator kernel
bool loadFromSource = Gbl.HasRawHashChanged[Gbl.RawDir.Scripts];
loadFromSource = true;
_chunkWidthInBlocks = Gbl.LoadContent<int>("TGen_ChunkWidthInBlocks");
_chunkWidthInVerts = _chunkWidthInBlocks + 1;
_blockWidth = Gbl.LoadContent<int>("TGen_BlockWidthInMeters");
float lacunarity = Gbl.LoadContent<float>("TGen_Lacunarity");
float gain = Gbl.LoadContent<float>("TGen_Gain");
int octaves = Gbl.LoadContent<int>("TGen_Octaves");
float offset = Gbl.LoadContent<float>("TGen_Offset");
float hScale = Gbl.LoadContent<float>("TGen_HScale");
float vScale = Gbl.LoadContent<float>("TGen_VScale");
_genConstants = new ComputeBuffer<float>(_context, ComputeMemoryFlags.ReadOnly, 8);
var genArr = new[]{
lacunarity,
gain,
offset,
octaves,
hScale,
vScale,
_blockWidth,
_chunkWidthInBlocks
};
_cmdQueue.WriteToBuffer(genArr, _genConstants, false, null);
if (loadFromSource){
_generationPrgm = new ComputeProgram(_context, Gbl.LoadScript("TGen_Generator"));
#if CPU_DEBUG
_generationPrgm.Build(null, @"-g -s D:\Projects\Gondola\Scripts\GenTerrain.cl", null, IntPtr.Zero); //use option -I + scriptDir for header search
#else
_generationPrgm.Build(null, "", null, IntPtr.Zero);//use option -I + scriptDir for header search
#endif
Gbl.SaveBinary(_generationPrgm.Binaries, "TGen_Generator");
}
else{
var binary = Gbl.LoadBinary("TGen_Generator");
_generationPrgm = new ComputeProgram(_context, binary, _devices);
_generationPrgm.Build(null, "", null, IntPtr.Zero);
}
//loadFromSource = false;
_terrainGenKernel = _generationPrgm.CreateKernel("GenTerrain");
_normalGenKernel = _generationPrgm.CreateKernel("GenNormals");
//despite the script using float3 for these fields, we need to consider it to be float4 because the
//implementation is basically a float4 wrapper that uses zero for the last variable
_geometry = new ComputeBuffer<float>(_context, ComputeMemoryFlags.None, _chunkWidthInVerts*_chunkWidthInVerts*4);
_normals = new ComputeBuffer<ushort>(_context, ComputeMemoryFlags.None, _chunkWidthInVerts * _chunkWidthInVerts * 4);
_binormals = new ComputeBuffer<byte>(_context, ComputeMemoryFlags.None, _chunkWidthInVerts*_chunkWidthInVerts*4);
_tangents = new ComputeBuffer<byte>(_context, ComputeMemoryFlags.None, _chunkWidthInVerts*_chunkWidthInVerts*4);
_uvCoords = new ComputeBuffer<float>(_context, ComputeMemoryFlags.None, _chunkWidthInVerts*_chunkWidthInVerts*2);
_terrainGenKernel.SetMemoryArgument(0, _genConstants);
_terrainGenKernel.SetMemoryArgument(3, _geometry);
_terrainGenKernel.SetMemoryArgument(4, _uvCoords);
_normalGenKernel.SetMemoryArgument(0, _genConstants);
_normalGenKernel.SetMemoryArgument(3, _geometry);
_normalGenKernel.SetMemoryArgument(4, _normals);
_normalGenKernel.SetMemoryArgument(5, _binormals);
_normalGenKernel.SetMemoryArgument(6, _tangents);
#endregion
#region setup quadtree kernel
if (loadFromSource){
_qTreePrgm = new ComputeProgram(_context, Gbl.LoadScript("TGen_QTree"));
#if CPU_DEBUG
_qTreePrgm.Build(null, @"-g -s D:\Projects\Gondola\Scripts\Quadtree.cl", null, IntPtr.Zero);
#else
_qTreePrgm.Build(null, "", null, IntPtr.Zero);
#endif
Gbl.SaveBinary(_qTreePrgm.Binaries, "TGen_QTree");
}
else{
var binary = Gbl.LoadBinary("TGen_QTree");
_qTreePrgm = new ComputeProgram(_context, binary, _devices);
_qTreePrgm.Build(null, "", null, IntPtr.Zero);
}
_qTreeKernel = _qTreePrgm.CreateKernel("QuadTree");
_crossCullKernel = _qTreePrgm.CreateKernel("CrossCull");
_activeVerts = new ComputeBuffer<byte>(_context, ComputeMemoryFlags.None, _chunkWidthInVerts*_chunkWidthInVerts);
//.........这里部分代码省略.........
示例3: EndSend
public unsafe void EndSend()
{
for (int i = 0; i < points.Count; i++)
{
inx[i].x = (float)points[i].Item3.Real;
inx[i].y = (float)points[i].Item3.Imaginary;
inc[i].x = (float)points[i].Item4.Real;
inc[i].y = (float)points[i].Item4.Imaginary;
}
_krnl.SetMemoryArgument(0, x);
_krnl.SetMemoryArgument(1, c);
for (int i = 0; i < _ld.Count; i++)
{
_krnl.SetMemoryArgument(2 + i, outp[i]);
}
ComputeCommandQueue command = new ComputeCommandQueue(_context, _context.Devices[0], ComputeCommandQueueFlags.None);
command.WriteToBuffer(inx, x, false, null);
command.WriteToBuffer(inc, c, false, null);
command.Execute(_krnl, null, new long[] { points.Count }, null, null);
for (int i = 0; i < _ld.Count; i++)
command.ReadFromBuffer(outp[i], ref opl[i], false, null);
command.Finish();
output = new Queue<Tuple<int, int, List<ProcessLayer>>>();
for (int i = 0; i < points.Count; i++)
{
List<ProcessLayer> pl = new List<ProcessLayer>();
for (int ii = 0; ii < _ld.Count; ii++)
{
ProcessLayer p = _ld[ii].Clone();
p.c_active = opl[ii][i].c_active != 0;
p.c_calc = opl[ii][i].c_calc;
p.c_cmean = opl[ii][i].c_cmean;
p.c_cvariance = opl[ii][i].c_cvariance;
p.c_cvarsx = opl[ii][i].c_cvarsx;
p.c_isin = opl[ii][i].c_isin != 0;
p.c_n = opl[ii][i].c_n;
p.c_old2x = new Complex(opl[ii][i].c_old2x.x,opl[ii][i].c_old2x.y);
p.c_oldx = new Complex(opl[ii][i].c_oldx.x,opl[ii][i].c_oldx.y);
p.c_resn = opl[ii][i].c_resn;
p.c_resx = new Complex(opl[ii][i].c_resx.x,opl[ii][i].c_resx.y);
p.c_x = new Complex(opl[ii][i].c_x.x,opl[ii][i].c_x.y);
pl.Add(p);
}
output.Enqueue(Tuple.Create(points[i].Item1, points[i].Item2, pl));
}
}
示例4: CalculateConvolution
private void CalculateConvolution(ComputeContext computeContext)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
float dx;
bool shiftXParse = float.TryParse(textBoxShiftX.Text, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out dx);
if (!shiftXParse)
throw new SyntaxErrorException(", needs to be .");
float dy;
bool shiftYParse = float.TryParse(textBoxShiftX.Text, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out dy);
if (!shiftYParse)
throw new SyntaxErrorException(", needs to be .");
float dz;
bool shiftZParse = float.TryParse(textBoxShiftX.Text, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out dz);
if (!shiftZParse)
throw new SyntaxErrorException(", needs to be .");
int pixelCount = _imageDimensionX*_imageDimensionY*_imageDimensionZ;
Console.WriteLine("Computing...");
Console.WriteLine("Reading kernel...");
String kernelPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
String kernelString;
using (var sr = new StreamReader(kernelPath + "\\convolution.cl"))
kernelString = sr.ReadToEnd();
Console.WriteLine("Reading kernel... done");
float[] selectedTransformation = Transformations.GetTransformation((TransformationType)comboBoxTransform.SelectedItem, 1.0f / float.Parse(textBoxPixelSize.Text), 1.0f / float.Parse(textBoxPixelSize.Text), 1.0f / float.Parse(textBoxPixelSize.Text), dx, dy, dz);
//create openCL program
ComputeProgram computeProgram = new ComputeProgram(computeContext, kernelString);
computeProgram.Build(computeContext.Devices, null, null, IntPtr.Zero);
ComputeProgramBuildStatus computeProgramBuildStatus = computeProgram.GetBuildStatus(_selectedComputeDevice);
Console.WriteLine("computeProgramBuildStatus\n\t"+computeProgramBuildStatus);
String buildLog = computeProgram.GetBuildLog(_selectedComputeDevice);
Console.WriteLine("buildLog");
if (buildLog.Equals("\n"))
Console.WriteLine("\tbuildLog is empty...");
else
Console.WriteLine("\t" + buildLog);
float[] fluorophores = CsvData.ReadFluorophores(_sourceFilename);
/////////////////////////////////////////////
// Create a Command Queue & Event List
/////////////////////////////////////////////
ComputeCommandQueue computeCommandQueue = new ComputeCommandQueue(computeContext, _selectedComputeDevice, ComputeCommandQueueFlags.None);
////////////////////////////////////////////////////////////////
// Create Buffers Transform
////////////////////////////////////////////////////////////////
ComputeBuffer<float> fluorophoresCoords = new ComputeBuffer<float>(computeContext, ComputeMemoryFlags.ReadWrite, fluorophores.LongLength);
ComputeBuffer<float> transformationMatrix = new ComputeBuffer<float>(computeContext, ComputeMemoryFlags.ReadOnly, selectedTransformation.LongLength);
/////////////////////////////////////////////
// Create the transformFluorophoresKernel
///////////////////////////////////////////////////////////
ComputeKernel transformFluorophoresKernel = computeProgram.CreateKernel("transform_fluorophores");
/////////////////////////////////////////////
// Set the transformFluorophoresKernel arguments
/////////////////////////////////////////////
transformFluorophoresKernel.SetMemoryArgument(0, fluorophoresCoords);
transformFluorophoresKernel.SetMemoryArgument(1, transformationMatrix);
/////////////////////////////////////////////
// Configure the work-item structure
/////////////////////////////////////////////
long[] globalWorkOffsetTransformFluorophoresKernel = null;
long[] globalWorkSizeTransformFluorophoresKernel = new long[] { fluorophores.Length / 4 };
long[] localWorkSizeTransformFluorophoresKernel = null;
////////////////////////////////////////////////////////
// Enqueue the transformFluorophoresKernel for execution
////////////////////////////////////////////////////////
computeCommandQueue.WriteToBuffer(fluorophores, fluorophoresCoords, true, null);
computeCommandQueue.WriteToBuffer(selectedTransformation, transformationMatrix, true, null);
computeCommandQueue.Execute(transformFluorophoresKernel, globalWorkOffsetTransformFluorophoresKernel, globalWorkSizeTransformFluorophoresKernel, localWorkSizeTransformFluorophoresKernel, null);
// computeCommandQueue.ExecuteTask(transformFluorophoresKernel, transformFluorophoresEvents);
float[] transformedFluorophores = new float[fluorophores.Length];
computeCommandQueue.ReadFromBuffer(fluorophoresCoords, ref transformedFluorophores, true, null);
computeCommandQueue.Finish();
//TODO remove, only for testing
// for (int i = 0; i < transformedFluorophores.Length; i++)
//.........这里部分代码省略.........
示例5: syncBuffer
/// <summary>
/// Copy the material data to the GPU.
/// </summary>
/// <param name="commandQueue"></param>
public void syncBuffer(ComputeCommandQueue commandQueue)
{
// TODO: try non-blocking sends.
commandQueue.WriteToBuffer<Material>(_materialArray, Buffer, true, null);
}