Beispiel #1
0
        public BuildStatus GetBuildStatus(Device device)
        {
            BuildInfo buildInfo;

            buildInfo = new BuildInfo(this, device);
            return((BuildStatus)InteropTools.ReadInt(buildInfo, (uint)ProgramBuildInfo.STATUS));
        }
Beispiel #2
0
        public string GetBuildLog(Device device)
        {
            BuildInfo buildInfo;

            buildInfo = new BuildInfo(this, device);
            return(InteropTools.ReadString(buildInfo, (uint)ProgramBuildInfo.LOG));
        }
Beispiel #3
0
        public Platform(IntPtr platformID)
        {
            this.PlatformID = platformID;

            // Create a local representation of all devices
            this.DeviceIDs = this.QueryDeviceIntPtr(DeviceType.ALL);
            for (var i = 0; i < this.DeviceIDs.Length; i++)
            {
                this._Devices[this.DeviceIDs[i]] = new Device(this, this.DeviceIDs[i]);
            }
            this.DeviceList = InteropTools.ConvertDeviceIDsToDevices(this, this.DeviceIDs);

            this.InitializeExtensionHashSet();

            var m = this.VersionStringRegex.Match(this.Version);

            if (m.Success)
            {
                this.OpenCLMajorVersion = Int32.Parse(m.Groups["Major"].Value);
                this.OpenCLMinorVersion = Int32.Parse(m.Groups["Minor"].Value);
            }
            else
            {
                this.OpenCLMajorVersion = 1;
                this.OpenCLMinorVersion = 0;
            }
        }
        public static void HexDump(String filename, Byte[] array, Int32 width)
        {
            var sw = new StreamWriter(filename);

            InteropTools.HexDump(sw, array, width);
            sw.Close();
        }
Beispiel #5
0
        public Platform(IntPtr platformID)
        {
            PlatformID = platformID;

            // Create a local representation of all devices
            DeviceIDs = QueryDeviceIntPtr(DeviceType.ALL);
            for (int i = 0; i < DeviceIDs.Length; i++)
            {
                _Devices[DeviceIDs[i]] = new Device(this, DeviceIDs[i]);
            }
            DeviceList = InteropTools.ConvertDeviceIDsToDevices(this, DeviceIDs);

            InitializeExtensionHashSet();

            Match m = VersionStringRegex.Match(Version);

            if (m.Success)
            {
                OpenCLMajorVersion = int.Parse(m.Groups["Major"].Value);
                OpenCLMinorVersion = int.Parse(m.Groups["Minor"].Value);
            }
            else
            {
                OpenCLMajorVersion = 1;
                OpenCLMinorVersion = 0;
            }

            if (VersionCheck(1, 2))
            {
                AddExtensionSupport(new DirectX9Extension(this));
                AddExtensionSupport(new DirectX10Extension(this));
                AddExtensionSupport(new DirectX11Extension(this));
            }
        }
Beispiel #6
0
        internal Context(Platform platform, ContextProperties[] properties, Device[] devices)
        {
            IntPtr[]  intPtrProperties;
            IntPtr[]  deviceIDs;
            ErrorCode result;

            Platform  = platform;
            deviceIDs = InteropTools.ConvertDevicesToDeviceIDs(devices);

            intPtrProperties = new IntPtr[properties.Length];
            for (int i = 0; i < properties.Length; i++)
            {
                intPtrProperties[i] = new IntPtr((long)properties[i]);
            }

            ContextID = (IntPtr)OpenCL.CreateContext(intPtrProperties,
                                                     (uint)devices.Length,
                                                     deviceIDs,
                                                     null,
                                                     IntPtr.Zero,
                                                     out result);
            if (result != ErrorCode.SUCCESS)
            {
                throw new OpenCLException("CreateContext failed: " + result, result);
            }
            Is64BitContext = ContainsA64BitDevice();
        }
Beispiel #7
0
        public CLProgram CreateProgramWithBinary(Device[] devices, byte[][] binaries, ErrorCode[] binaryStatus)
        {
            IntPtr    programID;
            ErrorCode result;

            IntPtr[] lengths;
            int[]    binStatus = new int[binaryStatus.Length];

            lengths = new IntPtr[devices.Length];
            for (int i = 0; i < lengths.Length; i++)
            {
                lengths[i] = (IntPtr)binaries[i].Length;
            }
            programID = OpenCL.CreateProgramWithBinary(ContextID,
                                                       (uint)devices.Length,
                                                       InteropTools.ConvertDevicesToDeviceIDs(devices),
                                                       lengths,
                                                       binaries,
                                                       binStatus,
                                                       out result);
            for (int i = 0; i < binaryStatus.Length; i++)
            {
                binaryStatus[i] = (ErrorCode)binStatus[i];
            }
            if (result != ErrorCode.SUCCESS)
            {
                throw new OpenCLException("CreateProgramWithBinary failed with error code " + result, result);
            }
            return(new CLProgram(this, programID));
        }
Beispiel #8
0
        /// <summary>
        /// Block until the event fires
        /// </summary>
        /// <param name="_event"></param>
        public void WaitForEvent(Event _event)
        {
            Event[] event_list = new Event[1];

            event_list[0] = _event;
            OpenCL.WaitForEvents(1, InteropTools.ConvertEventsToEventIDs(event_list));
        }
Beispiel #9
0
        public string GetBuildOptions(Device device)
        {
            BuildInfo buildInfo;

            buildInfo = new BuildInfo(this, device);
            return(InteropTools.ReadString(buildInfo, (uint)ProgramBuildInfo.OPTIONS));
        }
Beispiel #10
0
        /// <summary>
        /// Find all devices of a specififc type
        /// </summary>
        /// <param name="deviceType"></param>
        /// <returns>Array containing the devices</returns>
        public Device[] QueryDevices(DeviceType deviceType)
        {
            IntPtr[] deviceIDs;

            deviceIDs = QueryDeviceIntPtr(deviceType);
            return(InteropTools.ConvertDeviceIDsToDevices(this, deviceIDs));
        }
Beispiel #11
0
        public Context CreateContext(IntPtr[] contextProperties, Device[] devices, ContextNotify notify, IntPtr userData)
        {
            IntPtr    contextID;
            ErrorCode result;

            IntPtr[] deviceIDs = InteropTools.ConvertDevicesToDeviceIDs(devices);
            contextID = (IntPtr)OpenCL.CreateContext(contextProperties,
                                                     (uint)deviceIDs.Length,
                                                     deviceIDs,
                                                     notify,
                                                     userData,
                                                     out result);
            if (result != ErrorCode.SUCCESS)
            {
                throw new OpenCLException("CreateContext failed with error code: " + result, result);
            }
            return(new Context(this, contextID));
        }
        public static unsafe IntPtr[] ReadIntPtrArray(IPropertyContainer propertyContainer, UInt32 key)
        {
            var size        = propertyContainer.GetPropertySize(key);
            var numElements = (Int64)size / sizeof(IntPtr);
            var ptrs        = new IntPtr[numElements];
            var data        = InteropTools.ReadBytes(propertyContainer, key);

            fixed(Byte *pData = data)
            {
                var pBS = (void **)pData;

                for (var i = 0; i < numElements; i++)
                {
                    ptrs[i] = new IntPtr(pBS[i]);
                }
            }

            return(ptrs);
        }
Beispiel #13
0
        public unsafe Device[] GetDeviceIDsFromD3D11(Platform platform, D3D11DeviceSource d3d_device_source, IntPtr d3d_object, D3D11DeviceSet d3d_device_set)
        {
            ErrorCode status;
            uint      numDevices;

            status = GetDeviceIDsFromD3D11(platform, d3d_device_source, d3d_object, d3d_device_set, 0, null, &numDevices);
            if (status != ErrorCode.SUCCESS)
            {
                return(null);
            }

            IntPtr[] deviceArray = new IntPtr[numDevices];
            status = GetDeviceIDsFromD3D11(platform, d3d_device_source, d3d_object, d3d_device_set, numDevices, deviceArray, &numDevices);
            if (status != ErrorCode.SUCCESS)
            {
                return(null);
            }

            return(InteropTools.ConvertDeviceIDsToDevices(platform, deviceArray));
        }
Beispiel #14
0
        unsafe public static ulong[] ReadULongArray(IPropertyContainer propertyContainer, uint key)
        {
            IntPtr size        = propertyContainer.GetPropertySize(key);
            long   numElements = (long)size / sizeof(ulong);

            ulong[] ulongs = new ulong[numElements];
            byte[]  data   = InteropTools.ReadBytes(propertyContainer, key);

            fixed(byte *pData = data)
            {
                ulong *pBS = (ulong *)pData;

                for (int i = 0; i < numElements; i++)
                {
                    ulongs[i] = pBS[i];
                }
            }

            return(ulongs);
        }
Beispiel #15
0
        unsafe public static IntPtr[] ReadIntPtrArray(IPropertyContainer propertyContainer, uint key)
        {
            IntPtr size        = propertyContainer.GetPropertySize(key);
            long   numElements = (long)size / sizeof(IntPtr);

            IntPtr[] ptrs = new IntPtr[numElements];
            byte[]   data = InteropTools.ReadBytes(propertyContainer, key);

            fixed(byte *pData = data)
            {
                void **pBS = (void **)pData;

                for (int i = 0; i < numElements; i++)
                {
                    ptrs[i] = new IntPtr(pBS[i]);
                }
            }

            return(ptrs);
        }
Beispiel #16
0
        public void Build(Device[] devices, String options, ProgramNotify notify, IntPtr userData)
        {
            var deviceLength = 0;

            if (devices != null)
            {
                deviceLength = devices.Length;
            }

            var deviceIDs = InteropTools.ConvertDevicesToDeviceIDs(devices);
            var result    = OpenCL.BuildProgram(this.ProgramID,
                                                (UInt32)deviceLength,
                                                deviceIDs,
                                                options,
                                                notify,
                                                userData);

            if (result != ErrorCode.SUCCESS)
            {
                throw new OpenCLBuildException(this, result);
            }
        }
Beispiel #17
0
        public void Build(Device[] devices, string options, ProgramNotify notify, IntPtr userData)
        {
            ErrorCode result;

            IntPtr[] deviceIDs;
            int      deviceLength = 0;

            if (devices != null)
            {
                deviceLength = devices.Length;
            }

            deviceIDs = InteropTools.ConvertDevicesToDeviceIDs(devices);
            result    = (ErrorCode)OpenCL.BuildProgram(ProgramID,
                                                       (uint)deviceLength,
                                                       deviceIDs,
                                                       options,
                                                       notify,
                                                       userData);
            if (result != ErrorCode.SUCCESS)
            {
                throw new OpenCLBuildException(this, result);
            }
        }
Beispiel #18
0
        public String GetBuildOptions(Device device)
        {
            var buildInfo = new BuildInfo(this, device);

            return(InteropTools.ReadString(buildInfo, (UInt32)ProgramBuildInfo.OPTIONS));
        }
 public static Boolean ReadBool(IPropertyContainer propertyContainer, UInt32 key)
 {
     return(InteropTools.ReadUInt(propertyContainer, key) == (UInt32)Bool.TRUE ? true : false);
 }
Beispiel #20
0
 /// <summary>
 /// Block until all events in the array have fired
 /// </summary>
 /// <param name="num_events"></param>
 /// <param name="event_list"></param>
 public void WaitForEvents(int num_events, Event[] event_list)
 {
     OpenCL.WaitForEvents((uint)num_events, InteropTools.ConvertEventsToEventIDs(event_list));
 }
Beispiel #21
0
        public String GetBuildLog(Device device)
        {
            var buildInfo = new BuildInfo(this, device);

            return(InteropTools.ReadString(buildInfo, (UInt32)ProgramBuildInfo.LOG));
        }