public void CanInvokeFunction() { Device device = new Device(testContext); string code = @"function (I[N]) -> (O) { O[i: N] = +(I[k]), i - k < N; }"; Function f = new Function(testContext, code); DeviceTensor i = new DeviceTensor(device, new Compiler.PlaidML.Shape(testContext, PlaidmlDatatype.PLAIDML_DATA_INT32, 6), "I"); DeviceTensor o = new DeviceTensor(device, new Compiler.PlaidML.Shape(testContext, PlaidmlDatatype.PLAIDML_DATA_INT32, 6), "O"); Int32[] input_data = { 0, 1, 3, 4, 5, 6 }; i.CreateView <Int32>(MemoryMapType.Discard).CopyFromAndFree(input_data); DeviceTensorView <Int32> v = i.CreateView <Int32>(MemoryMapType.Retain); Assert.Equal(3, v[2]); Invoker <int> invoker = new Invoker <int>(testContext, f, new Compiler.PlaidML.DeviceTensor[] { i }, new Compiler.PlaidML.DeviceTensor[] { o }); Compiler.PlaidML.Shape x = invoker.GetOutputShape("O"); Assert.True(x.ElementCount == 6); Assert.True(invoker.AllVariablesSet); Invocation <Int32> inv = invoker.Invoke(); DeviceTensorView <Int32> R = o.CreateView <Int32>(MemoryMapType.Retain); Assert.Equal(6, R.ElementCount); Assert.Equal(4, R[2]); }
public void CanConstructShape() { Compiler.PlaidML.Shape s = new Compiler.PlaidML.Shape(testContext, PlaidmlDatatype.PLAIDML_DATA_FLOAT32, 4); Assert.True(s.IsAllocated); Assert.Equal(PlaidmlDatatype.PLAIDML_DATA_FLOAT32, s.DataType); Assert.Equal(1ul, s.DimensionCount); (ulong size, long stride) = s.Dimensions[0]; Assert.Equal(4ul, size); Assert.Equal(1L, stride); }
public void CanConstructBuffer() { Device device = new Device(testContext); Compiler.PlaidML.Shape s1 = new Compiler.PlaidML.Shape(testContext, PlaidmlDatatype.PLAIDML_DATA_FLOAT32, 4, 8, 8); device.CreateBuffer(s1); Assert.Single(device.Buffers); DeviceBuffer buffer = device.Buffers[0]; Assert.Equal(8UL * 8 * 4 * 4, buffer.SizeInBytes); Compiler.PlaidML.Shape s2 = new Compiler.PlaidML.Shape(testContext, PlaidmlDatatype.PLAIDML_DATA_INT64, 13, 5); device.CreateBuffer(s2); buffer = device.Buffers[1]; Assert.Equal((13UL * 5 * 8), buffer.SizeInBytes); }
public void CanConstructMapping() { Device device = new Device(testContext); Compiler.PlaidML.Shape s1 = new Compiler.PlaidML.Shape(testContext, PlaidmlDatatype.PLAIDML_DATA_FLOAT64, 4, 8, 8); device.CreateBuffer(s1); Assert.Single(device.Buffers); DeviceBuffer buffer = device.Buffers[0]; Assert.Equal(8UL * 8 * 4 * 8, buffer.SizeInBytes); MemoryMapping m = new MemoryMapping(buffer); Span <long> span = m.GetSpan <long>(); Assert.Equal((int)s1.ElementCount, span.Length); }
public void CanConstructTensorVariableView() { Device device = new Device(testContext); Compiler.PlaidML.Shape s1 = new Compiler.PlaidML.Shape(testContext, PlaidmlDatatype.PLAIDML_DATA_FLOAT64, 2, 3); DeviceTensor t = new DeviceTensor(device, s1, "t"); DeviceTensorView <Int64> v = t.CreateView <Int64>(MemoryMapType.Discard); Int64[,] array = { { 0, 1, 3 }, { 4, 5, 6 } }; v.CopyFromAndFree(array.Flatten <Int64>().ToArray()); Assert.Throws <InvalidOperationException>(() => v.Free()); DeviceTensorView <Int64> v2 = t.CreateView <long>(MemoryMapType.Retain); Assert.Equal(3, v2[2]); Assert.Equal(6, v2[5]); }