Exemplo n.º 1
0
        public ComputeContext(ICollection <ComputeDevice> devices, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr notifyDataPtr)
        {
            int handleCount;

            CLDeviceHandle[] deviceHandles = ComputeTools.ExtractHandles(devices, out handleCount);
            IntPtr[]         propertyArray = (properties != null) ? properties.ToIntPtrArray() : null;
            callback = notify;

            ComputeErrorCode error = ComputeErrorCode.Success;

            Handle = CL10.CreateContext(propertyArray, handleCount, deviceHandles, notify, notifyDataPtr, out error);
            ComputeException.ThrowOnError(error);

            SetID(Handle.Value);

            this.properties = properties;
            ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);

            this.platform = ComputePlatform.GetByHandle(platformProperty.Value);
            this.devices  = GetDevices();

#if DEBUG
            Trace.WriteLine("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
#endif
        }
Exemplo n.º 2
0
 public extern static CLContextHandle CreateContext(
     [MarshalAs(UnmanagedType.LPArray)] IntPtr[] properties,
     Int32 num_devices,
     [MarshalAs(UnmanagedType.LPArray)] CLDeviceHandle[] devices,
     ComputeContextNotifier pfn_notify,
     IntPtr user_data,
     out ComputeErrorCode errcode_ret);
        /// <summary>
        /// Creates a new context on a collection of devices.
        /// </summary>
        /// <param name="devices"> A collection of devices to associate with the context. </param>
        /// <param name="properties"> A list of context properties of the context. </param>
        /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the context. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until context is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param>
        /// <param name="notifyDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param>
        public IComputeContext CreateContext(ICollection <IComputeDevice> devices, List <ComputeContextProperty> properties,
                                             ComputeContextNotifier notify, IntPtr notifyDataPtr)
        {
            var context       = new ComputeContext200();
            var deviceHandles = ComputeTools.ExtractHandles(devices, out int handleCount);
            var propertyArray = context.ToIntPtrArray(properties);

            context.Handle = OpenCL200.CreateContext(
                propertyArray,
                handleCount,
                deviceHandles,
                notify,
                notifyDataPtr,
                out ComputeErrorCode error);
            ComputeException.ThrowOnError(error);

            context.SetID(context.Handle.Value);
            var platformProperty = context.GetByName(properties, ComputeContextPropertyName.Platform);

            context.Platform = ComputePlatform.GetByHandle(platformProperty.Value);
            context.Devices  = context.GetDevices();

            logger.Info("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
            return(context);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new context on all the devices that match the specified <see cref="ComputeDeviceTypes"/>.
        /// </summary>
        /// <param name="deviceType"> A bit-field that identifies the type of device to associate with the context. </param>
        /// <param name="properties"> A list of context properties of the context. </param>
        /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the context. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until context is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param>
        /// <param name="userDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param>
        public IComputeContext CreateContext(ComputeDeviceTypes deviceType, List <ComputeContextProperty> properties,
                                             ComputeContextNotifier notify, IntPtr userDataPtr)
        {
            var context       = new ComputeContext100();
            var propertyArray = context.ToIntPtrArray(properties);

            context.Handle = OpenCL100.CreateContextFromTypeWrapper(propertyArray, deviceType, notify, userDataPtr);
            context.SetID(context.Handle.Value);
            var platformProperty = context.GetByName(properties, ComputeContextPropertyName.Platform);

            context.Platform = ComputePlatform.GetByHandle(platformProperty.Value);
            context.Devices  = context.GetDevices();
            logger.Info("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
            return(context);
        }
Exemplo n.º 5
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Creates a new <see cref="ComputeContext"/> on all the <see cref="ComputeDevice"/>s that match
        /// the specified <see cref="ComputeDeviceTypes"/>.
        /// </summary>
        ///
        /// <param name="deviceType">   A bit-field that identifies the type of
        ///                             <see cref="ComputeDevice"/> to associate with the
        ///                             <see cref="ComputeContext"/>. </param>
        /// <param name="properties">   A <see cref="ComputeContextPropertyList"/> of the
        ///                             <see cref="ComputeContext"/>. </param>
        /// <param name="notify">       A delegate instance that refers to a notification routine. This
        ///                             routine is a callback function that will be used by the OpenCL
        ///                             implementation to report information on errors that occur in the
        ///                             <see cref="ComputeContext"/>. The callback function may be called
        ///                             asynchronously by the OpenCL implementation. It is the
        ///                             application's responsibility to ensure that the callback function
        ///                             is thread-safe and that the delegate instance doesn't get
        ///                             collected by the Garbage Collector until
        ///                             <see cref="ComputeContext"/> is disposed. If
        ///                             <paramref name="notify"/> is <c>null</c>, no callback function is
        ///                             registered. </param>
        /// <param name="userDataPtr">  Optional user data that will be passed to
        ///                             <paramref name="notify"/>. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public ComputeContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr)
        {
            IntPtr[] propertyArray = properties?.ToIntPtrArray();
            callback = notify;

            Handle = CL12.CreateContextFromType(propertyArray, deviceType, notify, userDataPtr, out var error);
            ComputeException.ThrowOnError(error);

            SetID(Handle.Value);

            this.properties = properties;
            ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);

            platform = ComputePlatform.GetByHandle(platformProperty.Value);
            devices  = GetDevices();

            RILogManager.Default?.SendTrace("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a new <see cref="ComputeContext"/> on all the <see cref="ComputeDevice"/>s that match the specified <see cref="ComputeDeviceTypes"/>.
        /// </summary>
        /// <param name="deviceType"> A bit-field that identifies the type of <see cref="ComputeDevice"/> to associate with the <see cref="ComputeContext"/>. </param>
        /// <param name="properties"> A <see cref="ComputeContextPropertyList"/> of the <see cref="ComputeContext"/>. </param>
        /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the <see cref="ComputeContext"/>. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until <see cref="ComputeContext"/> is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param>
        /// <param name="userDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param>
        public ComputeContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr)
        {
            IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null;
            callback = notify;

            ComputeErrorCode error = ComputeErrorCode.Success;

            Handle = CLInterface.CL12.CreateContextFromType(propertyArray, deviceType, notify, userDataPtr, out error);
            ComputeException.ThrowOnError(error);

            SetID(Handle.Value);

            this.properties = properties;
            ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);

            this.platform = ComputePlatform.GetByHandle(platformProperty.Value);
            this.devices  = GetDevices();
        }
Exemplo n.º 7
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Creates a new <see cref="ComputeContext"/> on a collection of <see cref="ComputeDevice"/>s.
        /// </summary>
        ///
        /// <param name="devices">          A collection of <see cref="ComputeDevice"/>s to associate
        ///                                 with the <see cref="ComputeContext"/>. </param>
        /// <param name="properties">       A <see cref="ComputeContextPropertyList"/> of the
        ///                                 <see cref="ComputeContext"/>. </param>
        /// <param name="notify">           A delegate instance that refers to a notification routine.
        ///                                 This routine is a callback function that will be used by the
        ///                                 OpenCL implementation to report information on errors that occur
        ///                                 in the <see cref="ComputeContext"/>. The callback function may be
        ///                                 called asynchronously by the OpenCL implementation. It is the
        ///                                 application's responsibility to ensure that the callback function
        ///                                 is thread-safe and that the delegate instance doesn't get
        ///                                 collected by the Garbage Collector until
        ///                                 <see cref="ComputeContext"/> is disposed. If
        ///                                 <paramref name="notify"/> is <c>null</c>, no callback function is
        ///                                 registered. </param>
        /// <param name="notifyDataPtr">    Optional user data that will be passed to
        ///                                 <paramref name="notify"/>. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public ComputeContext(ICollection <ComputeDevice> devices, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr notifyDataPtr)
        {
            CLDeviceHandle[] deviceHandles = ComputeTools.ExtractHandles(devices, out var handleCount);
            IntPtr[]         propertyArray = properties?.ToIntPtrArray();
            callback = notify;

            Handle = CL12.CreateContext(propertyArray, handleCount, deviceHandles, notify, notifyDataPtr, out var error);
            ComputeException.ThrowOnError(error);

            SetID(Handle.Value);

            this.properties = properties;
            ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);

            platform     = ComputePlatform.GetByHandle(platformProperty.Value);
            this.devices = GetDevices();

            RILogManager.Default?.SendTrace("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a new <see cref="ComputeContext"/> on all the <see cref="ComputeDevice"/>s that match the specified <see cref="ComputeDeviceTypes"/>.
        /// </summary>
        /// <param name="deviceType"> A bit-field that identifies the type of <see cref="ComputeDevice"/> to associate with the <see cref="ComputeContext"/>. </param>
        /// <param name="properties"> A <see cref="ComputeContextPropertyList"/> of the <see cref="ComputeContext"/>. </param>
        /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the <see cref="ComputeContext"/>. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until <see cref="ComputeContext"/> is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param>
        /// <param name="userDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param>
        public ComputeContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr)
        {
            IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null;
            callback = notify;

            ComputeErrorCode error = ComputeErrorCode.Success;

            Handle = CL12.CreateContextFromType(propertyArray, deviceType, notify, userDataPtr, out error);
            ComputeException.ThrowOnError(error);

            SetID(Handle.Value);

            this.properties = properties;
            ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);

            this.platform = ComputePlatform.GetByHandle(platformProperty.Value);
            this.devices  = GetDevices();

            Trace.WriteLine("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a new <see cref="ComputeContext"/> on a collection of <see cref="ComputeDevice"/>s.
        /// </summary>
        /// <param name="devices"> A collection of <see cref="ComputeDevice"/>s to associate with the <see cref="ComputeContext"/>. </param>
        /// <param name="properties"> A <see cref="ComputeContextPropertyList"/> of the <see cref="ComputeContext"/>. </param>
        /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the <see cref="ComputeContext"/>. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until <see cref="ComputeContext"/> is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param>
        /// <param name="notifyDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param>
        public ComputeContext(ICollection <ComputeDevice> devices, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr notifyDataPtr)
        {
            int handleCount;

            CLDeviceHandle[] deviceHandles = ComputeTools.ExtractHandles(devices, out handleCount);
            IntPtr[]         propertyArray = (properties != null) ? properties.ToIntPtrArray() : null;
            callback = notify;

            ComputeErrorCode error = ComputeErrorCode.Success;

            Handle = CLInterface.CL12.CreateContext(propertyArray, handleCount, deviceHandles, notify, notifyDataPtr, out error);
            ComputeException.ThrowOnError(error);

            SetID(Handle.Value);

            this.properties = properties;
            ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);

            this.platform = ComputePlatform.GetByHandle(platformProperty.Value);
            this.devices  = GetDevices();
        }
Exemplo n.º 10
0
 CLContextHandle ICL10.CreateContextFromType(IntPtr[] properties, ComputeDeviceTypes device_type,
                                             ComputeContextNotifier pfn_notify, IntPtr user_data,
                                             out ComputeErrorCode errcode_ret)
 {
     return(CreateContextFromType(properties, device_type, pfn_notify, user_data, out errcode_ret));
 }
Exemplo n.º 11
0
        public ComputeContext(ICollection <ComputeDevice> devices, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr notifyDataPtr)
        {
            IntPtr[] deviceHandles = ComputeTools.ExtractHandles(devices, out var handleCount);
            IntPtr[] propertyArray = properties?.ToIntPtrArray();

            handle = CL10.CreateContext(propertyArray, handleCount, deviceHandles, notify, notifyDataPtr, out _);

#if DEBUG
            Trace.WriteLine("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
#endif
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates a new <c>ComputeContext</c> on all the <c>ComputeDevice</c>s that match the specified <c>ComputeDeviceTypes</c>.
        /// </summary>
        /// <param name="deviceType"> A bit-field that identifies the type of <c>ComputeDevice</c> to associate with the <c>ComputeContext</c>. </param>
        /// <param name="properties"> A <c>ComputeContextPropertyList</c> of the <c>ComputeContext</c>. </param>
        /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the <c>ComputeContext</c>. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until <c>ComputeContext</c> is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param>
        /// <param name="userDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param>
        public ComputeContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr)
        {
            unsafe
            {
                IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null;
                callback = notify;

                ComputeErrorCode error = ComputeErrorCode.Success;
                Handle = CL10.CreateContextFromType(propertyArray, deviceType, notify, userDataPtr, &error);
                ComputeException.ThrowOnError(error);

                this.properties = properties;
                ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);
                this.platform = ComputePlatform.GetByHandle(platformProperty.Value);
                this.devices = GetDevices();
            }
        }
Exemplo n.º 13
0
 public static extern CLContextHandle CreateContextFromType(
     [MarshalAs(UnmanagedType.LPArray)] IntPtr[] properties,
     ComputeDeviceTypes device_type,
     ComputeContextNotifier pfn_notify,
     IntPtr user_data,
     out ComputeErrorCode errcode_ret);
Exemplo n.º 14
0
        public static CLContextHandle CreateContextFromTypeWrapper(IntPtr[] properties, ComputeDeviceTypes device_type, ComputeContextNotifier pfn_notify, IntPtr user_data)
        {
            var context = CreateContextFromType(properties, device_type, pfn_notify, user_data, out ComputeErrorCode errcode_ret);

            ComputeException.ThrowOnError(errcode_ret);
            return(context);
        }
Exemplo n.º 15
0
 public static unsafe extern IntPtr CreateContext(
     [MarshalAs(UnmanagedType.LPArray)] IntPtr[] properties,
     Int32 num_devices,
     [MarshalAs(UnmanagedType.LPArray)] IntPtr[] devices,
     /* void (*pfn_notify)(const char *, const IntPtr, IntPtr, IntPtr) */ ComputeContextNotifier pfn_notify,
     /* void* */ IntPtr user_data,
     ComputeErrorCode* errcode_ret);
Exemplo n.º 16
0
 CLContextHandle ICL10.CreateContext(IntPtr[] properties, int num_devices, CLDeviceHandle[] devices,
                                     ComputeContextNotifier pfn_notify, IntPtr user_data, out ComputeErrorCode errcode_ret)
 {
     return(CreateContext(properties, num_devices, devices, pfn_notify, user_data, out errcode_ret));
 }
Exemplo n.º 17
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="devices">list of devices</param>
 /// <param name="properties">context properties</param>
 /// <param name="notify">context notify</param>
 /// <param name="userDataPtr">user data pointer</param>
 public ClooContext(IEnumerable<ClooDevice> devices, ComputeContextPropertyList properties, ComputeContextNotifier notify, System.IntPtr userDataPtr)
     : base(devices.Cast<ComputeDevice>().ToList(), properties, notify, userDataPtr)
 {
     _devices.AddRange(devices);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="deviceType">device type</param>
 /// <param name="properties">context properties</param>
 /// <param name="notify">context notify</param>
 /// <param name="userDataPtr">user data pointer</param>
 public ClooContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, System.IntPtr userDataPtr)
     : base(deviceType, properties, notify, userDataPtr)
 {
     foreach (ComputeDevice device in base.Devices)
         _devices.Add(ClooDevice.FromBaseDevice(device));
 }
Exemplo n.º 19
0
        public static CLContextHandle CreateContextWrapper(IntPtr[] properties, int num_devices, CLDeviceHandle[] devices, ComputeContextNotifier pfn_notify, IntPtr user_data)
        {
            var context = CreateContext(properties, num_devices, devices, pfn_notify, user_data, out ComputeErrorCode errcode_ret);

            ComputeException.ThrowOnError(errcode_ret);
            return(context);
        }
Exemplo n.º 20
0
 public static extern IntPtr CreateContext([MarshalAs(UnmanagedType.LPArray)] IntPtr[] properties, int num_devices, [MarshalAs(UnmanagedType.LPArray)] IntPtr[] devices, ComputeContextNotifier pfn_notify, IntPtr user_data, out int errcode_ret);
Exemplo n.º 21
0
        /// <summary>
        /// Creates a new <see cref="ComputeContext"/> on all the <see cref="ComputeDevice"/>s that match the specified <see cref="ComputeDeviceTypes"/>.
        /// </summary>
        /// <param name="deviceType"> A bit-field that identifies the type of <see cref="ComputeDevice"/> to associate with the <see cref="ComputeContext"/>. </param>
        /// <param name="properties"> A <see cref="ComputeContextPropertyList"/> of the <see cref="ComputeContext"/>. </param>
        /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the <see cref="ComputeContext"/>. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until <see cref="ComputeContext"/> is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param>
        /// <param name="userDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param>
        public ComputeContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr)
        {
            unsafe
            {
                IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null;
                callback = notify;

                ComputeErrorCode error = ComputeErrorCode.Success;
                Handle = CL10.CreateContextFromType(propertyArray, deviceType, notify, userDataPtr, &error);
                ComputeException.ThrowOnError(error);

                this.properties = properties;
                ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);
                this.platform = ComputePlatform.GetByHandle(platformProperty.Value);
                this.devices = GetDevices();
            }

            resourceTable.Add(GetHashCode(), this);
            Trace.WriteLine("Created " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").");
        }
Exemplo n.º 22
0
        /// <summary>
        /// Creates a new <see cref="ComputeContext"/> on a collection of <see cref="ComputeDevice"/>s.
        /// </summary>
        /// <param name="devices"> A collection of <see cref="ComputeDevice"/>s to associate with the <see cref="ComputeContext"/>. </param>
        /// <param name="properties"> A <see cref="ComputeContextPropertyList"/> of the <see cref="ComputeContext"/>. </param>
        /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the <see cref="ComputeContext"/>. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until <see cref="ComputeContext"/> is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param>
        /// <param name="notifyDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param>
        public ComputeContext(ICollection<ComputeDevice> devices, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr notifyDataPtr)
        {
            int handleCount;
            CLDeviceHandle[] deviceHandles = ComputeTools.ExtractHandles(devices, out handleCount);
            IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null;
            callback = notify;

            ComputeErrorCode error = ComputeErrorCode.Success;
            Handle = CL10.CreateContext(propertyArray, handleCount, deviceHandles, notify, notifyDataPtr, out error);
            ComputeException.ThrowOnError(error);
            
            SetID(Handle.Value);
            
            this.properties = properties;
            ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);
            this.platform = ComputePlatform.GetByHandle(platformProperty.Value);
            this.devices = GetDevices();

            Trace.WriteLine("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
        }
Exemplo n.º 23
0
 public static extern CLContextHandle CreateContext(
     [MarshalAs(UnmanagedType.LPArray)] IntPtr[] properties,
     Int32 num_devices,
     [MarshalAs(UnmanagedType.LPArray)] CLDeviceHandle[] devices,
     ComputeContextNotifier pfn_notify,
     IntPtr user_data,
     out ComputeErrorCode errcode_ret);
Exemplo n.º 24
0
 CLContextHandle ICL10.CreateContext(IntPtr[] properties, int num_devices, CLDeviceHandle[] devices,
                                     ComputeContextNotifier pfn_notify, IntPtr user_data, out ComputeErrorCode errcode_ret)
 {
     return CreateContext(properties, num_devices, devices, pfn_notify, user_data, out errcode_ret);
 }
Exemplo n.º 25
0
 public extern static CLContextHandle CreateContextFromType(
     [MarshalAs(UnmanagedType.LPArray)] IntPtr[] properties,
     ComputeDeviceTypes device_type,
     ComputeContextNotifier pfn_notify,
     IntPtr user_data,
     out ComputeErrorCode errcode_ret);
Exemplo n.º 26
0
 CLContextHandle ICL10.CreateContextFromType(IntPtr[] properties, ComputeDeviceTypes device_type,
                                             ComputeContextNotifier pfn_notify, IntPtr user_data,
                                             out ComputeErrorCode errcode_ret)
 {
     return CreateContextFromType(properties, device_type, pfn_notify, user_data, out errcode_ret);
 }
Exemplo n.º 27
0
        /// <summary>
        /// Creates a new <c>ComputeContext</c> on a collection of <c>ComputeDevice</c>s.
        /// </summary>
        /// <param name="devices"> A collection of <c>ComputeDevice</c>s to associate with the <c>ComputeContext</c>. </param>
        /// <param name="properties"> A <c>ComputeContextPropertyList</c> of the <c>ComputeContext</c>. </param>
        /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the <c>ComputeContext</c>. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until <c>ComputeContext</c> is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param>
        /// <param name="notifyDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param>
        public ComputeContext(ICollection<ComputeDevice> devices, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr notifyDataPtr)
        {
            unsafe
            {
                IntPtr[] deviceHandles = Tools.ExtractHandles(devices);
                IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null;
                callback = notify;

                ComputeErrorCode error = ComputeErrorCode.Success;
                Handle = CL10.CreateContext(propertyArray, devices.Count, deviceHandles, notify, notifyDataPtr, &error);
                ComputeException.ThrowOnError(error);

                this.properties = properties;
                ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);
                this.platform = ComputePlatform.GetByHandle(platformProperty.Value);
                this.devices = GetDevices();
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Creates a new <c>ComputeContext</c> on a collection of <c>ComputeDevice</c>s.
        /// </summary>
        /// <param name="devices"> A collection of <c>ComputeDevice</c>s to associate with the <c>ComputeContext</c>. </param>
        /// <param name="properties"> A <c>ComputeContextPropertyList</c> of the <c>ComputeContext</c>. </param>
        /// <param name="notify"> A callback function that can be registered by the application. This callback function will be used by the OpenCL implementation to report information on errors that occur in the <c>ComputeContext</c>. This callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param>
        /// <param name="notifyDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param>
        public ComputeContext(ICollection<ComputeDevice> devices, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr notifyDataPtr)
        {
            unsafe
            {
                IntPtr[] deviceHandles = Tools.ExtractHandles(devices);
                IntPtr[] propertiesList = (properties != null) ? properties.ToIntPtrArray() : null;
                IntPtr notifyFuncPtr = (notify != null) ? Marshal.GetFunctionPointerForDelegate(notify) : IntPtr.Zero;

                ComputeErrorCode error = ComputeErrorCode.Success;
                fixed (IntPtr* propertiesPtr = propertiesList)
                fixed (IntPtr* deviceHandlesPtr = deviceHandles)
                    Handle = CL10.CreateContext(
                        propertiesPtr,
                        devices.Count,
                        deviceHandlesPtr,
                        notifyFuncPtr,
                        notifyDataPtr,
                        &error);
                ComputeException.ThrowOnError(error);

                this.properties = properties;
                ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);
                this.platform = ComputePlatform.GetByHandle(platformProperty.Value);
                this.devices = GetDevices();
            }
        }