Exemplo n.º 1
0
 public static extern CLMem clCreateSubBuffer(
     CLMem buffer,
     CLMemFlags flags,
     CLBufferCreateType buffer_create_type,
     [MarshalAs(UnmanagedType.LPStruct)]
     CLBufferRegion buffer_create_info,
     ref CLError errcode_ret);
Exemplo n.º 2
0
 public static extern CLMem clCreatePipe(
     CLContext context,
     CLMemFlags flags,
     uint pipe_packet_size,
     uint pipe_max_packets,
     [In] IntPtr[] properties,
     ref CLError errcode_ret);
Exemplo n.º 3
0
 public static extern IntPtr CreateContext(
     [In] IntPtr *properties,
     [In] int numDevices,
     [In] IntPtr *devices,
     [In] IntPtr callback,
     [In] IntPtr userData,
     [Out] out CLError errorCode);
Exemplo n.º 4
0
        internal static void ValidateBuild(CLProgram openclProgram, Device device, CLError error)
        {
            if (CLError.None != error)
            {
                SizeT bufferSize = SizeT.Zero;

                OpenCLError.Validate(OpenCLDriver.clGetProgramBuildInfo(openclProgram, device.CLDeviceID, CLProgramBuildInfo.Log, SizeT.Zero, IntPtr.Zero, ref bufferSize));

                byte[] buffer = new byte[(Int64)bufferSize];

                GCHandle bufferHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);

                try
                {
                    OpenCLError.Validate(OpenCLDriver.clGetProgramBuildInfo(openclProgram, device.CLDeviceID, CLProgramBuildInfo.Log, new SizeT(buffer.LongLength), bufferHandle.AddrOfPinnedObject(), ref bufferSize));

                    Int32 count = Array.IndexOf<byte>(buffer, 0);

                    throw new OpenCLBuildError(error, System.Text.Encoding.ASCII.GetString(buffer, 0, count < 0 ? buffer.Length : count).Trim());
                }
                finally
                {
                    bufferHandle.Free();
                }
            }
        }
Exemplo n.º 5
0
        internal static void ValidateBuild(CLProgram openclProgram, Device device, CLError error)
        {
            if (CLError.None != error)
            {
                SizeT bufferSize = SizeT.Zero;

                OpenCLError.Validate(OpenCLDriver.clGetProgramBuildInfo(openclProgram, device.CLDeviceID, CLProgramBuildInfo.Log, SizeT.Zero, IntPtr.Zero, ref bufferSize));

                byte[] buffer = new byte[(Int64)bufferSize];

                GCHandle bufferHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);

                try
                {
                    OpenCLError.Validate(OpenCLDriver.clGetProgramBuildInfo(openclProgram, device.CLDeviceID, CLProgramBuildInfo.Log, new SizeT(buffer.LongLength), bufferHandle.AddrOfPinnedObject(), ref bufferSize));

                    Int32 count = Array.IndexOf <byte>(buffer, 0);

                    throw new OpenCLBuildError(error, System.Text.Encoding.ASCII.GetString(buffer, 0, count < 0 ? buffer.Length : count).Trim());
                }
                finally
                {
                    bufferHandle.Free();
                }
            }
        }
Exemplo n.º 6
0
 internal static void Validate(CLError error)
 {
     if (error != CLError.None)
     {
         throw new OpenCLError(error);
     }
 }
Exemplo n.º 7
0
 public static extern CLMem clCreateFromGLTexture3D(
     CLContext context,
     CLMemFlags flags,
     int target,
     int miplevel,
     uint texture,
     ref CLError errcode_ret);
Exemplo n.º 8
0
 internal static void VerifyDisposed(bool disposing, CLError clStatus)
 {
     if (disposing)
     {
         ThrowIfFailed(clStatus);
     }
 }
Exemplo n.º 9
0
 public static void ThrowIfFailed(CLError clStatus)
 {
     if (clStatus != CLError.CL_SUCCESS)
     {
         throw new CLException(clStatus);
     }
 }
Exemplo n.º 10
0
 public static extern CLContext clCreateContext(
     [In] IntPtr[] properties,
     uint num_devices,
     [In] CLDeviceID[] devices,
     LoggingFunction pfn_notify,
     IntPtr user_data,
     ref CLError errcode_ret);
Exemplo n.º 11
0
 public static void ThrowIfFailed(CLError errorCode)
 {
     if (errorCode != CLError.CL_SUCCESS)
     {
         throw new CLException(errorCode);
     }
 }
Exemplo n.º 12
0
 public static extern CLProgram clCreateProgramWithBinary(
     CLContext context,
     uint num_devices,
     [In] CLDeviceID[] device_list,
     [In] SizeT[] lengths,
     [In] IntPtr[] binaries,
     [In, Out] int[] binary_status,
     ref CLError errcode_ret);
Exemplo n.º 13
0
 public static extern CLMem clCreateImage2D(
     CLContext context,
     CLMemFlags flags,
     ref CLImageFormat image_format,
     SizeT image_width,
     SizeT image_height,
     SizeT image_row_pitch,
     IntPtr host_ptr,
     ref CLError errcode_ret);
Exemplo n.º 14
0
 public static extern CLMem clCreateImage(
     CLContext context,
     CLMemFlags flags,
     [MarshalAs(UnmanagedType.LPStruct)]
     CLImageFormat image_format,
     [MarshalAs(UnmanagedType.LPStruct)]
     CLImageDesc image_desc,
     IntPtr host_ptr,
     ref CLError errcode_ret);
Exemplo n.º 15
0
        public static CommandQueue Create(Context context, Device device, CommandQueueProperties commandQueueProperties)
        {
            CLError error = CLError.None;

            CLCommandQueue openclCommandQueue = OpenCLDriver.clCreateCommandQueue(context.CLContext, device.CLDeviceID, (ManOCL.Internal.OpenCL.CLCommandQueueProperties)commandQueueProperties, ref error);

            OpenCLError.Validate(error);

            return(new CommandQueue(openclCommandQueue, context, device, commandQueueProperties));
        }
Exemplo n.º 16
0
 public static extern CLProgram clLinkProgram(
     CLContext context,
     uint num_devices,
     [In] CLDeviceID[] device_list,
     string options,
     uint num_input_programs,
     [In] CLProgram[] input_programs,
     NotifyFunction pfn_notify,
     IntPtr user_data,
     ref CLError errcode_ret);
Exemplo n.º 17
0
 public static extern IntPtr clEnqueueMapBuffer(
     CLCommandQueue command_queue,
     CLMem buffer,
     CLBool blocking_map,
     CLMapFlags map_flags,
     SizeT offset,
     SizeT cb,
     uint num_events_in_wait_list,
     [In] CLEvent[] event_wait_list,
     IntPtr e,
     ref CLError errcode_ret);
Exemplo n.º 18
0
        public static Context Create(Platforms platforms, Devices devices)
        {
            CLError error = CLError.None;

            // TODO: Add parameter pfn_notify (logging function)
            CLContext openclContext = OpenCLDriver.clCreateContext(GetContextProperties(platforms), devices.Count, devices.OpenCLDeviceArray, null, IntPtr.Zero, ref error);

            OpenCLError.Validate(error);

            return(new Context(openclContext, platforms, devices));
        }
Exemplo n.º 19
0
        public static Kernel Create(String name, CommandQueue commandQueue, Program sources, params Argument[] arguments)
        {
            CLError error = CLError.None;

            CLKernel openclKernel = OpenCLDriver.clCreateKernel(sources.CLProgram, name, ref error);

            Kernel result = new Kernel(openclKernel, sources, commandQueue, name.Length + 1);

            result.InitializeArguments(arguments);

            return(result);
        }
Exemplo n.º 20
0
        public static Program Create(String[] sources, Context context, Devices devices, String buildOptions)
        {
            CLError error = CLError.None;

            CLProgram openclProgram = OpenCLDriver.clCreateProgramWithSource(context.CLContext, sources.Length, sources, GetLengths(sources), ref error);

            OpenCLError.Validate(error);

            OpenCLBuildError.ValidateBuild(openclProgram, devices[0], OpenCLDriver.clBuildProgram(openclProgram, devices.Count, devices.OpenCLDeviceArray, buildOptions, null, IntPtr.Zero));

            return(new Program(openclProgram, sources, context, devices, buildOptions));
        }
Exemplo n.º 21
0
        public static DeviceSampler Create(Boolean normalizedCoords, AddressingMode addressingMode, FilterMode filterMode, Context context)
        {
            CLError error = new CLError();

            CLSampler sampler = OpenCLDriver.clCreateSampler(context.CLContext, normalizedCoords ? CLBool.True : CLBool.False, (CLAddressingMode)addressingMode, (CLFilterMode)filterMode, ref error);

            OpenCLError.Validate(error);

            return(new DeviceSampler()
            {
                openCLSampler = sampler
            });
        }
Exemplo n.º 22
0
 public static extern IntPtr clEnqueueMapImage(
     CLCommandQueue command_queue,
     CLMem image,
     CLBool blocking_map,
     CLMapFlags map_flags,
     SizeT[] origin,
     SizeT[] region,
     ref SizeT image_row_pitch,
     ref SizeT image_slice_pitch,
     uint num_events_in_wait_list,
     [In] CLEvent[] event_wait_list,
     IntPtr e,
     ref CLError errcode_ret);
Exemplo n.º 23
0
        public static DeviceSampler Create(Boolean normalizedCoords, AddressingMode addressingMode, FilterMode filterMode, Context context)
        {
            CLError error = new CLError();

            CLSampler sampler = OpenCLDriver.clCreateSampler(context.CLContext, normalizedCoords ? CLBool.True : CLBool.False, (CLAddressingMode)addressingMode, (CLFilterMode)filterMode, ref error);

            OpenCLError.Validate(error);

            return new DeviceSampler()
            {
                openCLSampler = sampler
            };
        }
Exemplo n.º 24
0
        public static void CreateAsync <T>(CreateCallback <T> createCallback, T userData, String[] sources, Devices devices, Context context, String buildOptions)
        {
            CLError error = CLError.None;

            CLProgram openclProgram = OpenCLDriver.clCreateProgramWithSource(context.CLContext, sources.Length, sources, GetLengths(sources), ref error);

            OpenCLError.Validate(error);

            Program program = new Program(openclProgram, sources, context, devices, buildOptions);

            program.AsyncHelperObject = new AsyncHelper <T>(program, createCallback, userData);

            OpenCLError.Validate(OpenCLDriver.clBuildProgram(openclProgram, devices.Count, devices.OpenCLDeviceArray, buildOptions, program.AsyncCallback, IntPtr.Zero));
        }
Exemplo n.º 25
0
        public static DeviceImage CreateFromTexture2D(UInt32 texture, Int32 mipLevel, DeviceBufferAccess access, Context context)
        {
            CLError error = CLError.None;

            CLMem mem = ManOCL.Internal.OpenCL.OpenGL.OpenCLGLDriver.clCreateFromGLTexture2D(context.CLContext, GetMemFlags(access), 3553 /* GL_TEXTURE_2D */, mipLevel, texture, ref error);

            OpenCLError.Validate(error);

            DeviceImage result = new DeviceImage(new Mem {
                Value = mem.Value
            });

            return(result);
        }
Exemplo n.º 26
0
        public static IntPtr ShareForMac(IntPtr cglShareGroup)
        {
            CLError error = CLError.None;

            IntPtr[] properties =
            {
                new IntPtr(0x10000000), // CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE
                cglShareGroup,
                new IntPtr(0)
            };


            // TODO: Add parameter pfn_notify (logging function)
            CLContext openclContext = OpenCLDriver.clCreateContext(properties, 0, null, null, IntPtr.Zero, ref error);

            OpenCLError.Validate(error);

            return(openclContext.Value);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Multiply an array by a constant value
        /// </summary>
        internal static void Multiply()
        {
            try
            {
                CLError err = new CLError();
                //Allocate memory
                float[]  arr          = new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
                GCHandle arrGC        = GCHandle.Alloc(arr, GCHandleType.Pinned);
                CLMem    bufferFilter = OpenCLDriver.clCreateBuffer(ctx, CLMemFlags.ReadWrite | CLMemFlags.CopyHostPtr, new SizeT(arr.Length * sizeof(float)), arrGC.AddrOfPinnedObject(), ref err);

                //set parameters
                unsafe
                {
                    OpenCLDriver.clSetKernelArg(kernel_mult, 0, new SizeT(sizeof(CLMem)), ref bufferFilter);
                }

                //Define grid & execute
                err = OpenCLDriver.clFinish(comQ);
                SizeT[] localws  = { 5, 1 };
                SizeT[] globalws = { 10, 1 };
                CLEvent eventObj = new CLEvent();
                err = OpenCLDriver.clEnqueueNDRangeKernel(comQ, kernel_mult, 2, null,
                                                          globalws, localws, 0, null, ref eventObj);
                CLEvent[] eventObjs = new CLEvent[1];
                eventObjs[0] = eventObj;
                OpenCLDriver.clWaitForEvents(1, eventObjs);
                // read buffer
                err = OpenCLDriver.clEnqueueReadBuffer(comQ, bufferFilter, CLBool.True, 0,
                                                       10 * sizeof(float), arrGC.AddrOfPinnedObject(), 0, null, ref eventObj);

                TableForm.ShowTableStatic(arr, "OpenCL Test");
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString());
            }
        }
Exemplo n.º 28
0
 internal static extern IntPtr clEnqueueMapBuffer(CLCommandQueue command_queue, CLMem buffer, CLBool blocking_map, CLMapFlags map_flags, SizeT offset, SizeT cb, int num_events_in_wait_list, [In] CLEvent[] event_wait_list, ref CLEvent e, ref CLError errcode_ret);
Exemplo n.º 29
0
 internal static extern CLProgram clCreateProgramWithBinary(CLContext context, int num_devices, [In] CLDeviceID[] device_list, [In] SizeT[] lengths, [In] IntPtr[] binaries, [In] int[] binary_status, ref CLError errcode_ret);
Exemplo n.º 30
0
 internal static extern CLError clCreateFromGLRenderbuffer(CLContext context, CLMemFlags flags, int renderbuffer, ref CLError errcode_ret);
Exemplo n.º 31
0
 public static extern CLMem clCreateFromGLBuffer(
     CLContext context,
     CLMemFlags flags,
     uint bufobj,
     ref CLError errcode_ret);
Exemplo n.º 32
0
 internal static extern CLContext clCreateContext([In] IntPtr[] properties, int num_devices, [In] CLDeviceID[] devices, LoggingFunction pfn_notify, IntPtr user_data, ref CLError errcode_ret);
Exemplo n.º 33
0
 internal static extern CLContext clCreateContextFromType([In] IntPtr[] properties, CLDeviceType device_type, LoggingFunction pfn_notify, IntPtr user_data, ref CLError errcode_ret);
Exemplo n.º 34
0
 internal static extern IntPtr clEnqueueMapImage(CLCommandQueue command_queue, CLMem image, CLBool blocking_map, CLMapFlags map_flags, SizeT[] origin, SizeT[] region, ref SizeT image_row_pitch, ref SizeT image_slice_pitch, int num_events_in_wait_list, [In] CLEvent[] event_wait_list, ref CLEvent e, ref CLError errcode_ret);
Exemplo n.º 35
0
 internal static extern CLProgram clCreateProgramWithSource(CLContext context, int count, [In] string[] strings, [In] SizeT[] lengths, ref CLError errcode_ret);
Exemplo n.º 36
0
 internal static extern CLCommandQueue clCreateCommandQueue(CLContext context, CLDeviceID device, CLCommandQueueProperties properties, ref CLError errcode_ret);
Exemplo n.º 37
0
 public OpenCLBuildError(CLError error, String buildLog)
     : base(error)
 {
     this.BuildLog = buildLog;
 }
Exemplo n.º 38
0
 internal static extern CLMem clCreateBuffer(CLContext context, CLMemFlags flags, SizeT size, IntPtr host_ptr, ref CLError errcode_ret);
Exemplo n.º 39
0
 public static extern CLMem clCreateFromGLRenderbuffer(
     CLContext context,
     CLMemFlags flags,
     uint renderbuffer,
     ref CLError errcode_ret);
Exemplo n.º 40
0
 internal OpenCLError(CLError errorCode)
 {
     this.ErrorCode = errorCode;
 }
Exemplo n.º 41
0
 internal static extern CLMem clCreateFromGLTexture3D(CLContext context, CLMemFlags flags, int target, int miplevel, uint texture, ref CLError errcode_ret);
Exemplo n.º 42
0
 /// <summary>
 /// Constructs a new OpenCL exception.
 /// </summary>
 /// <param name="errorCode">The OpenCL runtime error.</param>
 public CLException(CLError errorCode)
     : base()
 {
     Error = errorCode;
 }
Exemplo n.º 43
0
 internal static extern CLError clCreateFromGLBuffer(CLContext context, CLMemFlags flags, int bufobj, ref CLError errcode_ret);
Exemplo n.º 44
0
 internal static extern CLKernel clCreateKernel(CLProgram program, string kernel_name, ref CLError errcode_ret);
Exemplo n.º 45
0
        public static Context ShareWithCGL(IntPtr cglShareGroup)
        {
            IntPtr[] properties =
            {
                new IntPtr(0x10000000),                 // CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE
                cglShareGroup,
                new IntPtr(0)
            };

            CLError error = CLError.None;

            // TODO: Add parameter pfn_notify (logging function)
            CLContext openclContext = OpenCLDriver.clCreateContext(properties, 0, null, null, IntPtr.Zero, ref error);

            OpenCLError.Validate(error);

            SizeT devicesSize = SizeT.Zero;

            OpenCLError.Validate(OpenCLDriver.clGetContextInfo(openclContext, CLContextInfo.Devices, SizeT.Zero, IntPtr.Zero, ref devicesSize));

            CLDeviceID[] devices = new CLDeviceID[((Int64)(devicesSize)) / IntPtr.Size];

            GCHandle devicesHandle = GCHandle.Alloc(devices, GCHandleType.Pinned);

            try
            {
                OpenCLError.Validate(OpenCLDriver.clGetContextInfo(openclContext, CLContextInfo.Devices, devicesSize, devicesHandle.AddrOfPinnedObject(), ref devicesSize));

                Dictionary <CLPlatformID, CLPlatformID> platformsDictionary = new Dictionary <CLPlatformID, CLPlatformID>();

                CLPlatformID[] platforms = null;

                foreach (CLDeviceID device in devices)
                {
                    SizeT platformsSize = SizeT.Zero;

                    OpenCLError.Validate(OpenCLDriver.clGetDeviceInfo(device, CLDeviceInfo.Platform, SizeT.Zero, platforms, ref platformsSize));

                    platforms = new CLPlatformID[((Int64)(platformsSize)) / IntPtr.Size];

                    OpenCLError.Validate(OpenCLDriver.clGetDeviceInfo(device, CLDeviceInfo.Platform, platformsSize, platforms, ref platformsSize));

                    foreach (CLPlatformID platform in platforms)
                    {
                        if (!platformsDictionary.ContainsKey(platform))
                        {
                            platformsDictionary.Add(platform, platform);
                        }
                    }
                }

                platforms = new CLPlatformID[platformsDictionary.Count];

                Int32 index = 0;

                foreach (var platform in platformsDictionary.Keys)
                {
                    platforms[index++] = platform;
                }

                return(new Context(openclContext, new Platforms(platforms), new Devices(devices)));
            }
            finally
            {
                devicesHandle.Free();
            }
        }
Exemplo n.º 46
0
        /// <summary>
        /// Multiply an array by a constant value
        /// </summary>
        internal static void Multiply()
        {
            try
            {
                CLError err = new CLError();
                //Allocate memory
                float[] arr = new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
                GCHandle arrGC = GCHandle.Alloc(arr, GCHandleType.Pinned);
                CLMem bufferFilter = OpenCLDriver.clCreateBuffer(ctx, CLMemFlags.ReadWrite | CLMemFlags.CopyHostPtr, new SizeT(arr.Length * sizeof(float)), arrGC.AddrOfPinnedObject(), ref err);

                //set parameters
                unsafe
                {
                    OpenCLDriver.clSetKernelArg(kernel_mult, 0, new SizeT(sizeof(CLMem)), ref bufferFilter);
                }

                //Define grid & execute
                err = OpenCLDriver.clFinish(comQ);
                SizeT[] localws = { 5, 1 };
                SizeT[] globalws = { 10, 1 };
                CLEvent eventObj = new CLEvent();
                err = OpenCLDriver.clEnqueueNDRangeKernel(comQ, kernel_mult, 2, null,
                globalws, localws, 0, null, ref eventObj);
                CLEvent[] eventObjs = new CLEvent[1];
                eventObjs[0] = eventObj;
                OpenCLDriver.clWaitForEvents(1, eventObjs);
                // read buffer
                err = OpenCLDriver.clEnqueueReadBuffer(comQ, bufferFilter, CLBool.True, 0,
                10 * sizeof(float), arrGC.AddrOfPinnedObject(), 0, null, ref eventObj);

                TableForm.ShowTableStatic(arr, "OpenCL Test");

            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString());
            }
        }
Exemplo n.º 47
0
 public OpenCLBuildError(CLError error, String buildLog)
     : base(error)
 {
     this.BuildLog = buildLog;
 }
Exemplo n.º 48
0
 internal static extern CLSampler clCreateSampler(CLContext context, CLBool normalized_coords, CLAddressingMode addressing_mode, CLFilterMode filter_mode, ref CLError errcode_ret);
Exemplo n.º 49
0
 internal static void Validate(CLError error)
 {
     if (error != CLError.None) throw new OpenCLError(error);
 }
Exemplo n.º 50
0
 internal static extern CLMem clCreateImage3D(CLContext context, CLMemFlags flags, ref CLImageFormat image_format, SizeT image_width, SizeT image_height, SizeT image_depth, SizeT image_row_pitch, SizeT image_slice_pitch, IntPtr host_ptr, ref CLError errcode_ret);