示例#1
0
        public void CreateImageTests()
        {
            ErrorCode error;

            if (Cl.GetDeviceInfo(_device, DeviceInfo.ImageSupport, out error).CastTo <Bool>() == Bool.False)
            {
                Console.WriteLine("No image support");
                return;
            }

            {
                var  image2DData = new float[200 * 200 * sizeof(float)];
                IMem image2D     = Cl.CreateImage2D(_context, MemFlags.CopyHostPtr | MemFlags.ReadOnly, new ImageFormat(ChannelOrder.RGBA, ChannelType.Float),
                                                    (IntPtr)200, (IntPtr)200, (IntPtr)0, image2DData, out error);
                Assert.AreEqual(error, ErrorCode.Success);

                Assert.AreEqual(Cl.GetImageInfo(image2D, ImageInfo.Width, out error).CastTo <uint>(), 200);
                Assert.AreEqual(Cl.GetImageInfo(image2D, ImageInfo.Height, out error).CastTo <uint>(), 200);

                image2D.Dispose();
            }

            {
                var  image3DData = new float[200 * 200 * 200 * sizeof(float)];
                IMem image3D     = Cl.CreateImage3D(_context, MemFlags.CopyHostPtr | MemFlags.ReadOnly, new ImageFormat(ChannelOrder.RGBA, ChannelType.Float),
                                                    (IntPtr)200, (IntPtr)200, (IntPtr)200, IntPtr.Zero, IntPtr.Zero, image3DData, out error);
                Assert.AreEqual(error, ErrorCode.Success);

                Assert.AreEqual(Cl.GetImageInfo(image3D, ImageInfo.Width, out error).CastTo <uint>(), 200);
                Assert.AreEqual(Cl.GetImageInfo(image3D, ImageInfo.Height, out error).CastTo <uint>(), 200);
                Assert.AreEqual(Cl.GetImageInfo(image3D, ImageInfo.Depth, out error).CastTo <uint>(), 200);

                image3D.Dispose();
            }
        }
示例#2
0
        public void MemBufferTests()
        {
            const int bufferSize = 100;

            ErrorCode error;
            Random    random = new Random();

            float[] values = (from value in Enumerable.Range(0, bufferSize) select(float) random.NextDouble()).ToArray();
            IMem    buffer = Cl.CreateBuffer(_context, MemFlags.CopyHostPtr | MemFlags.ReadOnly, (IntPtr)(sizeof(float) * bufferSize), values, out error);

            Assert.AreEqual(error, ErrorCode.Success);

            Assert.AreEqual(Cl.GetMemObjectInfo(buffer, MemInfo.Type, out error).CastTo <MemObjectType>(), MemObjectType.Buffer);
            Assert.AreEqual(Cl.GetMemObjectInfo(buffer, MemInfo.Size, out error).CastTo <uint>(), values.Length * sizeof(float));

            // TODO: Verify values
            //int index = 0;
            //foreach (float value in Cl.GetMemObjectInfo(buffer, Cl.MemInfo.HostPtr, out error).CastToEnumerable<float>(Enumerable.Range(0, 100)))
            //{
            //    Assert.AreEqual(values[index], value);
            //    index++;
            //}

            buffer.Dispose();
        }
示例#3
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.
                buf.Dispose();

                disposedValue = true;
            }
        }
 public void Dispose()
 {
     _d_stocksAndPrices.Dispose();
     _d_output.Dispose();
     _env.Dispose();
 }