Beispiel #1
0
        /// <summary>
        /// Get platform and device info
        /// </summary>
        internal static void GetInfo()
        {
            try
            {
                uint num_entries = 0;
                uint num_entries_devices = 0;
                // get device
                CLPlatformID[] platforms = new CLPlatformID[5];
                CLError err = OpenCLDriver.clGetPlatformIDs(5, platforms, ref num_entries);
                if (err != CLError.Success) throw new Exception(err.ToString());
                if (num_entries == 0) throw new Exception("No Platform Entries found!");
                // get platform properties
                byte[] buffer = new byte[1000];
                GCHandle bufferGC = GCHandle.Alloc(buffer, GCHandleType.Pinned);
                SizeT buffSize, buffSizeOut = new SizeT();
                for (int i = 0; i < num_entries; i++)
                {
                    buffSize = new CASS.Types.SizeT(1000);
                    err = OpenCLDriver.clGetPlatformInfo(platforms[i], CLPlatformInfo.Name, buffSize,
                    bufferGC.AddrOfPinnedObject(), ref buffSizeOut);
                    if (err != CLError.Success) throw new Exception(err.ToString());
                    MessageBox.Show("Platform: " + i + "\n" + System.Text.Encoding.ASCII.GetString(buffer));

                    CLDeviceID[] devices = new CLDeviceID[2];
                    err = OpenCLDriver.clGetDeviceIDs(platforms[i], CLDeviceType.All, 2, devices, ref num_entries_devices);
                    if (err != CLError.Success) throw new Exception(err.ToString());

                    string result = "";
                    err = OpenCLDriver.clGetDeviceInfo(devices[0], CLDeviceInfo.Vendor, buffSize,
                    bufferGC.AddrOfPinnedObject(), ref buffSizeOut);
                    result += CLDeviceInfo.Vendor.ToString() + ": " +
                    Encoding.ASCII.GetString(buffer, 0, buffSizeOut - 1) + "\n";
                    buffSize = new CASS.Types.SizeT(1000);
                    err = OpenCLDriver.clGetDeviceInfo(devices[0], CLDeviceInfo.Name, buffSize,
                    bufferGC.AddrOfPinnedObject(), ref buffSizeOut);
                    result += CLDeviceInfo.Name.ToString() + ": " +
                    Encoding.ASCII.GetString(buffer, 0, buffSizeOut - 1) + "\n";

                    int[] workDim = new int[1];
                    bufferGC = GCHandle.Alloc(workDim, GCHandleType.Pinned);
                    buffSize = new CASS.Types.SizeT(sizeof(int));
                    err = OpenCLDriver.clGetDeviceInfo(devices[0], CLDeviceInfo.MaxComputeUnits, buffSize,
                    bufferGC.AddrOfPinnedObject(), ref buffSizeOut);
                    result += CLDeviceInfo.MaxComputeUnits.ToString() + ": " + workDim[0] + "\n";
                    err = OpenCLDriver.clGetDeviceInfo(devices[0], CLDeviceInfo.MaxWorkItemDimensions,
                    workDim.Length * sizeof(int), bufferGC.AddrOfPinnedObject(), ref buffSizeOut);
                    result += CLDeviceInfo.MaxWorkItemDimensions.ToString() + ": " + workDim[0] + "\n";
                    SizeT[] sizeWI = new SizeT[workDim[0]];
                    bufferGC = GCHandle.Alloc(sizeWI, GCHandleType.Pinned);
                    err = OpenCLDriver.clGetDeviceInfo(devices[0], CLDeviceInfo.MaxWorkItemSizes, sizeWI.Length *
                    sizeof(int), bufferGC.AddrOfPinnedObject(), ref buffSizeOut);
                    result += CLDeviceInfo.MaxWorkItemSizes.ToString() + ": " +
                    sizeWI[0] + "x" + sizeWI[1] + "x" + sizeWI[2] + "\n";
                    MessageBox.Show(result, "Device");

                }

            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString());
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get platform and device info
        /// </summary>
        internal static void GetInfo()
        {
            try
            {
                uint num_entries         = 0;
                uint num_entries_devices = 0;
                // get device
                CLPlatformID[] platforms = new CLPlatformID[5];
                CLError        err       = OpenCLDriver.clGetPlatformIDs(5, platforms, ref num_entries);
                if (err != CLError.Success)
                {
                    throw new Exception(err.ToString());
                }
                if (num_entries == 0)
                {
                    throw new Exception("No Platform Entries found!");
                }
                // get platform properties
                byte[]   buffer = new byte[1000];
                GCHandle bufferGC = GCHandle.Alloc(buffer, GCHandleType.Pinned);
                SizeT    buffSize, buffSizeOut = new SizeT();
                for (int i = 0; i < num_entries; i++)
                {
                    buffSize = new CASS.Types.SizeT(1000);
                    err      = OpenCLDriver.clGetPlatformInfo(platforms[i], CLPlatformInfo.Name, buffSize,
                                                              bufferGC.AddrOfPinnedObject(), ref buffSizeOut);
                    if (err != CLError.Success)
                    {
                        throw new Exception(err.ToString());
                    }
                    MessageBox.Show("Platform: " + i + "\n" + System.Text.Encoding.ASCII.GetString(buffer));

                    CLDeviceID[] devices = new CLDeviceID[2];
                    err = OpenCLDriver.clGetDeviceIDs(platforms[i], CLDeviceType.All, 2, devices, ref num_entries_devices);
                    if (err != CLError.Success)
                    {
                        throw new Exception(err.ToString());
                    }

                    string result = "";
                    err = OpenCLDriver.clGetDeviceInfo(devices[0], CLDeviceInfo.Vendor, buffSize,
                                                       bufferGC.AddrOfPinnedObject(), ref buffSizeOut);
                    result += CLDeviceInfo.Vendor.ToString() + ": " +
                              Encoding.ASCII.GetString(buffer, 0, buffSizeOut - 1) + "\n";
                    buffSize = new CASS.Types.SizeT(1000);
                    err      = OpenCLDriver.clGetDeviceInfo(devices[0], CLDeviceInfo.Name, buffSize,
                                                            bufferGC.AddrOfPinnedObject(), ref buffSizeOut);
                    result += CLDeviceInfo.Name.ToString() + ": " +
                              Encoding.ASCII.GetString(buffer, 0, buffSizeOut - 1) + "\n";

                    int[] workDim = new int[1];
                    bufferGC = GCHandle.Alloc(workDim, GCHandleType.Pinned);
                    buffSize = new CASS.Types.SizeT(sizeof(int));
                    err      = OpenCLDriver.clGetDeviceInfo(devices[0], CLDeviceInfo.MaxComputeUnits, buffSize,
                                                            bufferGC.AddrOfPinnedObject(), ref buffSizeOut);
                    result += CLDeviceInfo.MaxComputeUnits.ToString() + ": " + workDim[0] + "\n";
                    err     = OpenCLDriver.clGetDeviceInfo(devices[0], CLDeviceInfo.MaxWorkItemDimensions,
                                                           workDim.Length * sizeof(int), bufferGC.AddrOfPinnedObject(), ref buffSizeOut);
                    result += CLDeviceInfo.MaxWorkItemDimensions.ToString() + ": " + workDim[0] + "\n";
                    SizeT[] sizeWI = new SizeT[workDim[0]];
                    bufferGC = GCHandle.Alloc(sizeWI, GCHandleType.Pinned);
                    err      = OpenCLDriver.clGetDeviceInfo(devices[0], CLDeviceInfo.MaxWorkItemSizes, sizeWI.Length *
                                                            sizeof(int), bufferGC.AddrOfPinnedObject(), ref buffSizeOut);
                    result += CLDeviceInfo.MaxWorkItemSizes.ToString() + ": " +
                              sizeWI[0] + "x" + sizeWI[1] + "x" + sizeWI[2] + "\n";
                    MessageBox.Show(result, "Device");
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString());
            }
        }