本文整理汇总了C#中Worker.Malloc方法的典型用法代码示例。如果您正苦于以下问题:C# Worker.Malloc方法的具体用法?C# Worker.Malloc怎么用?C# Worker.Malloc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Worker
的用法示例。
在下文中一共展示了Worker.Malloc方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateLayer
public static Layer CreateLayer(Worker worker, int inputs, int outputs, int kernelDim, string fnameWeights,string fnameBias)
{
var pathWeights = Data.GetPath(fnameWeights);
var pathBias = Data.GetPath(fnameBias);
var dataH = Data.ReadBinaryFile(pathWeights);
var dataD = worker.Malloc(dataH);
var biasH = Data.ReadBinaryFile(pathBias);
var biasD = worker.Malloc(biasH);
return new Layer
{
Inputs = inputs,
Outputs = outputs,
KernelDim = kernelDim,
DataH = dataH,
DataD = dataD,
BiasH = biasH,
BiasD = biasD
};
}
示例2: SimWindow
//.........这里部分代码省略.........
//[CreateSimulatros]
_simulators = new Queue<ISimulator>();
var target = GPUModuleTarget.Worker(_worker);
var simulatorGpuDynamicBlockSizeModule = new GpuDynamicSimulatorModule(target); // need dispose
var simulatorGpuDynamicBlockSize64 = simulatorGpuDynamicBlockSizeModule.Create(64);
var simulatorGpuDynamicBlockSize128 = simulatorGpuDynamicBlockSizeModule.Create(128);
var simulatorGpuDynamicBlockSize256 = simulatorGpuDynamicBlockSizeModule.Create(256);
var simulatorGpuDynamicBlockSize512 = simulatorGpuDynamicBlockSizeModule.Create(512);
var simulatorGpuStaticBlockSizeModule64 = new GpuStaticSimulatorModule64(target); // need dispose
var simulatorGpuStaticBlockSizeModule128 = new GpuStaticSimulatorModule128(target); // need dispose
var simulatorGpuStaticBlockSizeModule256 = new GpuStaticSimulatorModule256(target); // need dispose
var simulatorGpuStaticBlockSizeModule512 = new GpuStaticSimulatorModule512(target); // need dispose
// First, enquene one simulator which is 256 blocksize so we can compare with C code for performance.
_simulators.Enqueue(simulatorGpuStaticBlockSizeModule256);
// Enqueue several dynamic block size simulators.
_simulators.Enqueue(simulatorGpuDynamicBlockSize64);
_simulators.Enqueue(simulatorGpuDynamicBlockSize128);
_simulators.Enqueue(simulatorGpuDynamicBlockSize256);
_simulators.Enqueue(simulatorGpuDynamicBlockSize512);
// Enqueue several static block size simulators.
_simulators.Enqueue(simulatorGpuStaticBlockSizeModule64);
_simulators.Enqueue(simulatorGpuStaticBlockSizeModule128);
_simulators.Enqueue(simulatorGpuStaticBlockSizeModule256);
_simulators.Enqueue(simulatorGpuStaticBlockSizeModule512);
// We do not enqueue any cpu simulator as it is much too slow.
//_simulators.Enqueue(new CpuSimulator(_worker, _numBodies));
_disposeSimulators = () =>
{
simulatorGpuDynamicBlockSizeModule.Dispose();
simulatorGpuStaticBlockSizeModule64.Dispose();
simulatorGpuStaticBlockSizeModule128.Dispose();
simulatorGpuStaticBlockSizeModule256.Dispose();
simulatorGpuStaticBlockSizeModule512.Dispose();
};
_simulator = _simulators.Dequeue();
//[/CreateSimulatros]
//[CreateBuffers]
_buffers = new uint[2];
for (var i = 0; i < _buffers.Length; i++)
{
_buffers[i] = 0;
}
GL.GenBuffers(_buffers.Length, _buffers);
foreach (var buffer in _buffers)
{
GL.BindBuffer(BufferTarget.ArrayBuffer, buffer);
GL.BufferData(BufferTarget.ArrayBuffer,
(IntPtr) (Microsoft.FSharp.Core.Operators.SizeOf<float4>()*_numBodies),
IntPtr.Zero, BufferUsageHint.DynamicDraw);
var size = 0;
unsafe
{
GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, &size);
}
if (size != Microsoft.FSharp.Core.Operators.SizeOf<float4>()*_numBodies)
{
throw new Exception("Pixel Buffer Object allocation failed!");
}
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
CUDAInterop.cuSafeCall(CUDAInterop.cuGLRegisterBufferObject(buffer));
}
_resources = new IntPtr[_buffers.Length];
for (var i = 0; i < _buffers.Length; i++)
{
var res = IntPtr.Zero;
unsafe
{
CUDAInterop.cuSafeCall(CUDAInterop.cuGraphicsGLRegisterBuffer(&res, _buffers[i], 0u));
}
_resources[i] = res;
}
//[/CreateBuffers]
//[FinalizeGL]
_vel = _worker.Malloc<float4>(_numBodies);
float4[] hpos, hvel;
BodyInitializer.Initialize(new BodyInitializer3(), clusterScale, velocityScale, _numBodies,
out hpos, out hvel);
_worker.Scatter(hvel, _vel.Ptr, Microsoft.FSharp.Core.FSharpOption<int>.None,
Microsoft.FSharp.Core.FSharpOption<int>.None);
LockPos(
(pos0, pos1) =>
_worker.Scatter(hpos, pos1, Microsoft.FSharp.Core.FSharpOption<int>.None,
Microsoft.FSharp.Core.FSharpOption<int>.None));
Help();
Description();
//[/FinalizeGL]
}