当前位置: 首页>>代码示例>>C#>>正文


C# Cloo.ComputeContext类代码示例

本文整理汇总了C#中Cloo.ComputeContext的典型用法代码示例。如果您正苦于以下问题:C# ComputeContext类的具体用法?C# ComputeContext怎么用?C# ComputeContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ComputeContext类属于Cloo命名空间,在下文中一共展示了ComputeContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderKernel

 private RenderKernel(ComputeContext context, ComputeKernel kernel, string[] sourcecodes, Dictionary<string, string> defines)
 {
     _context = context;
     _kernel = kernel;
     _sourcecodes = sourcecodes;
     _defines = defines;
 }
开发者ID:khyperia,项目名称:Clam,代码行数:7,代码来源:RenderKernel.cs

示例2: ComputeImage

        private ComputeImage(CLMemoryHandle handle, ComputeContext context, ComputeMemoryFlags flags)
            : base(context, flags)
        {
            Handle = handle;

            Init();
        }
开发者ID:nathanpackard,项目名称:openCLoo,代码行数:7,代码来源:ComputeImage.cs

示例3: ComputeImage2D

        /// <summary>
        /// Creates a new <see cref="ComputeImage2D"/> from a <c>Bitmap</c>.
        /// </summary>
        /// <param name="context"> A valid <see cref="ComputeContext"/> in which the <see cref="ComputeImage2D"/> is created. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeImage2D"/>. </param>
        /// <param name="bitmap"> The bitmap to use. </param>
        /// <remarks> Note that only bitmaps with <c>Alpha</c>, <c>Format16bppRgb555</c>, <c>Format16bppRgb565</c> or <c>Format32bppArgb</c> pixel formats are currently supported. </remarks>
        public ComputeImage2D(ComputeContext context, ComputeMemoryFlags flags, Bitmap bitmap)
            : base(context, flags)
        {
            unsafe
            {
                ComputeImageFormat format = Tools.ConvertImageFormat(bitmap.PixelFormat);
                BitmapData bitmapData = bitmap.LockBits(new Rectangle(new Point(), bitmap.Size), ImageLockMode.ReadOnly, bitmap.PixelFormat);

                ComputeErrorCode error = ComputeErrorCode.Success;
                Handle = CL10.CreateImage2D(
                    context.Handle,
                    flags,
                    &format,
                    new IntPtr(bitmap.Width),
                    new IntPtr(bitmap.Height),
                    new IntPtr(bitmapData.Stride),
                    bitmapData.Scan0,
                    &error);
                ComputeException.ThrowOnError(error);

                bitmap.UnlockBits(bitmapData);

                Init();
            }
        }
开发者ID:kwaegel,项目名称:Cloox2,代码行数:32,代码来源:ComputeImage2D.cs

示例4: OpenCLProxy

        public OpenCLProxy(bool useSoftware = false)
        {
            HardwareAccelerationEnabled = ComputePlatform.Platforms.Count != 0 && !useSoftware;

            if (HardwareAccelerationEnabled)
            {
                ComputePlatform platform = ComputePlatform.Platforms[0];
                var devices = new List<ComputeDevice> { platform.Devices[0] };
                var properties = new ComputeContextPropertyList(platform);

                _context = new ComputeContext(devices, properties, null, IntPtr.Zero);
                _commands = new ComputeCommandQueue(_context, _context.Devices[0], ComputeCommandQueueFlags.None);

                _intComputeBuffers = new Dictionary<string, ComputeBuffer<int>>();
                _floatComputeBuffers = new Dictionary<string, ComputeBuffer<float>>();

                AcceleratorName = platform.Name;
            }
            else
            {
                AcceleratorName = "CPU";
            }

            _intArguments = new Dictionary<string, int>();
            _intBuffers = new Dictionary<string, int[]>();

            _floatArguments = new Dictionary<string, float>();
            _floatBuffers = new Dictionary<string, float[]>();

            _doubleArguments = new Dictionary<string, double>();
        }
开发者ID:rdancer,项目名称:SpaceSim,代码行数:31,代码来源:OpenCLProxy.cs

示例5: Run

        public void Run(ComputeContext context, TextWriter log)
        {
            try
            {
                ComputeProgram program = new ComputeProgram(context, kernelSources);
                program.Build(null, null, null, IntPtr.Zero);
                log.WriteLine("Program successfully built.");
                ICollection<ComputeKernel> kernels = program.CreateAllKernels();
                log.WriteLine("Kernels successfully created.");

                // cleanup kernels
                foreach (ComputeKernel kernel in kernels)
                {
                    kernel.Dispose();
                }
                kernels.Clear();

                // cleanup program
                program.Dispose();
            }
            catch (Exception e)
            {
                log.WriteLine(e.ToString());
            }
        }
开发者ID:RokkiGH,项目名称:cloo-unity,代码行数:25,代码来源:MultipleKernelsExample.cs

示例6: ComputeImage3D

        private ComputeImage3D(IntPtr handle, ComputeContext context, ComputeMemoryFlags flags)
            : base(context, flags)
        {
            Handle = handle;

            Init();
        }
开发者ID:yeerkkiller1,项目名称:Go-AI,代码行数:7,代码来源:ComputeImage3D.cs

示例7: Initialize

        public virtual void Initialize() {
            platform = ComputePlatform.Platforms[0];
            device = platform.Devices[0];

            properties = new ComputeContextPropertyList(platform);
            context = new ComputeContext(new[] { device }, properties, null, IntPtr.Zero);
            program = new ComputeProgram(context, KernelSrc);
        }
开发者ID:HungryBear,项目名称:rayden,代码行数:8,代码来源:ClDeviceContext.cs

示例8: ComputePipe

 /// <summary>
 /// 
 /// </summary>
 /// <param name="context"></param>
 /// <param name="flags"></param>
 /// <param name="packetSize"></param>
 /// <param name="maxPackets"></param>
 public ComputePipe(ComputeContext context, ComputeMemoryFlags flags, int packetSize, int maxPackets)
     : this(context, flags)
 {
     ComputeErrorCode error;
     Handle = CLInterface.CL20.CreatePipe(context.Handle, flags, packetSize, maxPackets, null, out error);
     ComputeException.ThrowOnError(error);
     Init();
 }
开发者ID:nathanpackard,项目名称:openCLoo,代码行数:15,代码来源:ComputePipe.cs

示例9: buttonCalculate_Click

        private void buttonCalculate_Click(object sender, EventArgs e)
        {
            SetOutputDimensions();

            // construct context
            var context = new ComputeContext(_selectedComputeDevice.Type, new ComputeContextPropertyList(_selectedComputePlatform), null, IntPtr.Zero);

            CalculateConvolution(context);
        }
开发者ID:jalmar,项目名称:DoM_Utrecht-GPU,代码行数:9,代码来源:Form1.cs

示例10: ComputeImage3D

        /// <summary>
        /// Creates a new <see cref="ComputeImage3D"/>.
        /// </summary>
        /// <param name="context"> A valid <see cref="ComputeContext"/> in which the <see cref="ComputeImage3D"/> is created. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeImage3D"/>. </param>
        /// <param name="format"> A structure that describes the format properties of the <see cref="ComputeImage3D"/>. </param>
        /// <param name="width"> The width of the <see cref="ComputeImage3D"/> in pixels. </param>
        /// <param name="height"> The height of the <see cref="ComputeImage3D"/> in pixels. </param>
        /// <param name="depth"> The depth of the <see cref="ComputeImage3D"/> in pixels. </param>
        /// <param name="rowPitch"> The size in bytes of each row of elements of the <see cref="ComputeImage3D"/>. If <paramref name="rowPitch"/> is zero, OpenCL will compute the proper value based on <see cref="ComputeImage.Width"/> and <see cref="ComputeImage.ElementSize"/>. </param>
        /// <param name="slicePitch"> The size in bytes of each 2D slice in the <see cref="ComputeImage3D"/>. If <paramref name="slicePitch"/> is zero, OpenCL will compute the proper value based on <see cref="ComputeImage.RowPitch"/> and <see cref="ComputeImage.Height"/>. </param>
        /// <param name="data"> The data to initialize the <see cref="ComputeImage3D"/>. Can be <c>IntPtr.Zero</c>. </param>
        public ComputeImage3D(ComputeContext context, ComputeMemoryFlags flags, ComputeImageFormat format, int width, int height, int depth, long rowPitch, long slicePitch, IntPtr data)
            : base(context, flags)
        {
            ComputeErrorCode error = ComputeErrorCode.Success;
            Handle = CL10.CreateImage3D(context.Handle, flags, ref format, new IntPtr(width), new IntPtr(height), new IntPtr(depth), new IntPtr(rowPitch), new IntPtr(slicePitch), data, out error);
            ComputeException.ThrowOnError(error);

            Init();
        }
开发者ID:Dutchman97,项目名称:ConcurrencyPracticum3,代码行数:21,代码来源:ComputeImage3D.cs

示例11: LoadFromXml

 public static RenderPackage? LoadFromXml(ComputeContext computeContext, KernelXmlFile kernelXml, IParameterSet oldParameterSetCache)
 {
     var kernel = RenderKernel.Create(computeContext, kernelXml.Files.Select(File.ReadAllText).ToArray());
     if (kernel == null)
         return null;
     var controls = kernelXml.ControlsFunc();
     if (oldParameterSetCache != null && controls.GetType() == oldParameterSetCache.GetType())
         controls = oldParameterSetCache;
     return new RenderPackage(kernel, controls);
 }
开发者ID:khyperia,项目名称:Clam,代码行数:10,代码来源:RenderPackage.cs

示例12: ComputeSampler

        /// <summary>
        /// ComputeSamplerWithProperties
        /// </summary>
        /// <param name="context"></param>
        /// <param name="sampler_properties"></param>
        /// <param name="error"></param>
        public ComputeSampler(ComputeContext context, ComputeSamplerInfo[] sampler_properties, out ComputeErrorCode error)
        {
            error = ComputeErrorCode.Success;
            Handle = CLInterface.CL20.CreateSamplerWithProperties(context.Handle, sampler_properties, out error);
            ComputeException.ThrowOnError(error);

            SetID(Handle.Value);

            this.context = context;
        }
开发者ID:nathanpackard,项目名称:openCLoo,代码行数:16,代码来源:ComputeSampler.cs

示例13: Run

        public static void Run(TextWriter log, ComputeContext context)
        {
            StartTest(log, "Vector addition test");

            try
            {
                int count = 10;
                float[] arrA = new float[count];
                float[] arrB = new float[count];
                float[] arrC = new float[count];

                Random rand = new Random();

                for (int i = 0; i < count; i++)
                {
                    arrA[i] = (float)(rand.NextDouble() * 100);
                    arrB[i] = (float)(rand.NextDouble() * 100);
                }

                ComputeBuffer<float> a = new ComputeBuffer<float>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, arrA);
                ComputeBuffer<float> b = new ComputeBuffer<float>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, arrB);
                ComputeBuffer<float> c = new ComputeBuffer<float>(context, ComputeMemoryFlags.WriteOnly, arrC.Length);

                ComputeProgram program = new ComputeProgram(context, kernelSource);
                program.Build(null, null, null, IntPtr.Zero);
                ComputeKernel kernel = program.CreateKernel("VectorAdd");
                kernel.SetMemoryArgument(0, a);
                kernel.SetMemoryArgument(1, b);
                kernel.SetMemoryArgument(2, c);

                ComputeCommandQueue commands = new ComputeCommandQueue(context, context.Devices[0], ComputeCommandQueueFlags.None);

                ICollection<ComputeEventBase> events = new Collection<ComputeEventBase>();

                // BUG: ATI Stream v2.2 crash if event list not null.
                commands.Execute(kernel, null, new long[] { count }, null, events);
                //commands.Execute(kernel, null, new long[] { count }, null, null);

                arrC = new float[count];
                GCHandle arrCHandle = GCHandle.Alloc(arrC, GCHandleType.Pinned);

                commands.Read(c, true, 0, count, arrCHandle.AddrOfPinnedObject(), events);

                arrCHandle.Free();

                for (int i = 0; i < count; i++)
                    log.WriteLine("{0} + {1} = {2}", arrA[i], arrB[i], arrC[i]);
            }
            catch (Exception e)
            {
                log.WriteLine(e.ToString());
            }

            EndTest(log, "Vector addition test");
        }
开发者ID:kwaegel,项目名称:Cloox2,代码行数:55,代码来源:VectorAddTest.cs

示例14: ComputeProgram

        /// <summary>
        /// Creates a new <see cref="ComputeProgram"/> from a source code string.
        /// </summary>
        /// <param name="context"> A <see cref="ComputeContext"/>. </param>
        /// <param name="source"> The source code for the <see cref="ComputeProgram"/>. </param>
        /// <remarks> The created <see cref="ComputeProgram"/> is associated with the <see cref="ComputeContext.Devices"/>. </remarks>
        public ComputeProgram(ComputeContext context, string source)
        {
            ComputeErrorCode error = ComputeErrorCode.Success;
            Handle = CLInterface.CL10.CreateProgramWithSource(context.Handle, 1, new string[] { source }, null, out error);
            ComputeException.ThrowOnError(error);

            SetID(Handle.Value);

            this.context = context;
            this.devices = context.Devices;
            this.source = new ReadOnlyCollection<string>(new string[] { source });
        }
开发者ID:nathanpackard,项目名称:openCLoo,代码行数:18,代码来源:ComputeProgram.cs

示例15: ComputeUserEvent

        /// <summary>
        /// Creates a new <see cref="ComputeUserEvent"/>.
        /// </summary>
        /// <param name="context"> The <see cref="ComputeContext"/> in which the <see cref="ComputeUserEvent"/> is created. </param>
        /// <remarks> Requires OpenCL 1.1. </remarks>
        public ComputeUserEvent(ComputeContext context)
        {
            ComputeErrorCode error;
            Handle = CLInterface.CL11.CreateUserEvent(context.Handle, out error);
            ComputeException.ThrowOnError(error);
            
            SetID(Handle.Value);

            Type = (ComputeCommandType)GetInfo<CLEventHandle, ComputeEventInfo, uint>(Handle, ComputeEventInfo.CommandType, CLInterface.CL12.GetEventInfo);
            Context = context;
            HookNotifier();
        }
开发者ID:RokkiGH,项目名称:cloo-unity,代码行数:17,代码来源:ComputeUserEvent.cs


注:本文中的Cloo.ComputeContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。