本文整理汇总了C#中System.Buffer.Read方法的典型用法代码示例。如果您正苦于以下问题:C# Buffer.Read方法的具体用法?C# Buffer.Read怎么用?C# Buffer.Read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Buffer
的用法示例。
在下文中一共展示了Buffer.Read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Do
static void Do()
{
var c = 4;
var inArr = new int32 [c];
for (int _i = 0; _i < c; _i++) { inArr[_i] = 2; }
inArr[c-2] = 1;
int32 size = inArr.Length;
var rules = new Rule[] {new Rule(1,2,3,0,0),new Rule(2,3,2,0,0),new Rule(2,1,0,0,0),new Rule(3,2,0,0,0)};
var nTermRules = (from rule in rules where rule.c > 0 select rule).ToArray();
int32 nTerms = 3;
string platformName = "*";
Cl.DeviceType deviceType = Cl.DeviceType.Default;
ComputeProvider provider;
try
{
provider = ComputeProvider.Create(platformName, deviceType);
}
catch (PlatformNotSupportedException ex)
{
Console.WriteLine(ex.Message);
return;
}
var commandQueue = new CommandQueue(provider, provider.Devices.First());
var bArr = new int32[size * size * nTerms * cellDataRepresentationLength];
var rulesArr = new uint32[nTermRules.Length * ruleRepresentationLength];
for (int i = 0; i < size; i++)
{
for (int j = 0; j < rules.Length; j++)
{
if (inArr[i] == (rules[j]).b && (rules[j]).c == 0)
{
var _base = (i * nTerms + (int)(rules[j].a - 1)) * cellDataRepresentationLength;
bArr[_base] = rules[j].a;
//bArr[_base + 1] = 0;
//bArr[_base + 2] = (rules[j].lblNum == 0 ? 1 : 0);
///bArr[_base + 3] = rules[j].lblNum;
//bArr[_base + 4] = rules[j].lblWeight;
}
}
}
for (int i = 0; i < nTermRules.Length; i++)
{
var _base = i * ruleRepresentationLength;
rulesArr[_base] = (uint32)(uint)(nTermRules[i].a << 16 | nTermRules[i].b);
rulesArr[_base + 1] = (uint32)(uint)nTermRules[i].c;
//rulesArr[_base + 3] = rules[i].lblNum;
//rulesArr[_base + 4] = rules[i].lblWeight;
}
var buffer = new Buffer<int32>(provider, Operations.ReadWrite, Memory.Device, bArr);
var rulesBuffer = new Buffer<uint32>(provider, Operations.ReadOnly, Memory.Device, rulesArr);
int32 rLength = nTermRules.Length;
var processRow = provider.Compile<_1D, int32, Buffer<int32>, Buffer<uint32>>(
(range, l, a, _rules) =>
from r in range
let i = r.GlobalID0
let nT = nTerms
let _base = nT * size
let res_id_base = (l * _base) + i * nT
let iter = provider.Loop(0, l, kIdx=>
from k in kIdx
let left_base_idx = (k * _base) + i * nTerms
let right_base_idx = ((l - k - 1) * _base) + (k + i + 1) * nTerms
let iter2 = provider.Loop(0, rLength, rIdxs =>
from rId in rIdxs
let rule_base = rId * ruleRepresentationLength
let rule_a_b = _rules[rule_base]
let rule_a = (int)((rule_a_b >> 16) & 0xFFFF)
let rule_b = (int)(rule_a_b & 0xFFFF)
let rule_c = (int)(_rules[rule_base + 1] | 0)
let res_id = res_id_base + ((int)(uint)rule_a - 1)
select new[]{(rule_c != 0
& rule_c == a[right_base_idx + (rule_c - 1)]
& rule_b == a[left_base_idx + (rule_b - 1)])
? a[res_id] <= rule_a
: ((Brahma.Set<int32>)null)})
select (Brahma.Set<int32>[])null)
select (Brahma.Set<int32>[])null);
for (int l = 1; l < size; l++)
{
commandQueue.Add(processRow.Run(new _1D(size - l), l, buffer, rulesBuffer)).Finish();
}
commandQueue.Add(buffer.Read(0, size * size * nTerms * cellDataRepresentationLength, bArr)).Finish();
toMatrix(bArr, (int)(size * nTerms * cellDataRepresentationLength));
buffer.Dispose();
//.........这里部分代码省略.........