public static int GetAmdDevicePciBusID(OpenCl.DotNetCore.Devices.Device device) { var deviceHandle = GetDeviceHandle(device); var deviceInformation = (OpenCl.DotNetCore.Interop.Devices.DeviceInformation)DeviceInformation.CL_DEVICE_TOPOLOGY_AMD; var temp = new byte[256]; var res = DevicesNativeApi.GetDeviceInformation(deviceHandle, (OpenCl.DotNetCore.Interop.Devices.DeviceInformation)DeviceInformation.CL_DEVICE_BOARD_NAME_AMD, new UIntPtr(256), temp, out UIntPtr rVal); var name = System.Text.Encoding.ASCII.GetString(temp).TrimEnd(char.MinValue); var result = DevicesNativeApi.GetDeviceInformation(deviceHandle, deviceInformation, UIntPtr.Zero, null, out UIntPtr returnValueSize); if (result != Result.Success) { throw new Exception($"The device information could not be retrieved. Error code: {result}."); } var output = new byte[returnValueSize.ToUInt32()]; result = DevicesNativeApi.GetDeviceInformation(deviceHandle, deviceInformation, new UIntPtr((uint)output.Length), output, out returnValueSize); if (result != Result.Success) { throw new Exception($"The device information could not be retrieved. Error code: {result}."); } var topology = ByteArrayToStructure <CL_device_topology_amd>(output); return((topology.type == CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD) ? topology.bus : -1); }
/// <summary> /// Gets all devices of the platform that match the specified device type. /// </summary> /// <param name="deviceType">The type of devices that is to be retrieved.</param> /// <exception cref="OpenClException">If the devices could not be retrieved, then a <see cref="OpenClException"/> is thrown.</exception> /// <returns>Returns a list of all devices that matched the specified device type.</returns> public IEnumerable <Device> GetDevices(Devices.DeviceType deviceType) { // Gets the number of available devices of the specified type uint numberOfAvailableDevices; Result result = DevicesNativeApi.GetDeviceIds(Handle, (Interop.Devices.DeviceType)deviceType, 0, null, out numberOfAvailableDevices); if (result != Result.Success) { throw new OpenClException("The number of available devices could not be queried.", result); } // Gets the pointers to the devices of the specified type IntPtr[] devicePointers = new IntPtr[numberOfAvailableDevices]; result = DevicesNativeApi.GetDeviceIds(Handle, (Interop.Devices.DeviceType)deviceType, numberOfAvailableDevices, devicePointers, out numberOfAvailableDevices); if (result != Result.Success) { throw new OpenClException("The devices could not be retrieved.", result); } // Converts the pointer to device objects foreach (IntPtr devicePointer in devicePointers) { yield return(new Device(devicePointer)); } }
/// <summary> /// Retrieves the specified information about the device. /// </summary> /// <typeparam name="T">The type of the data that is to be returned.</param> /// <param name="deviceInformation">The kind of information that is to be retrieved.</param> /// <exception cref="OpenClException">If the information could not be retrieved, then an <see cref="OpenClException"/> is thrown.</exception> /// <returns>Returns the specified information.</returns> public T GetDeviceInformation <T>(DeviceInformation deviceInformation) { // Retrieves the size of the return value in bytes, this is used to later get the full information UIntPtr returnValueSize; Result result = DevicesNativeApi.GetDeviceInformation(Handle, deviceInformation, UIntPtr.Zero, null, out returnValueSize); if (result != Result.Success) { throw new OpenClException("The device information could not be retrieved.", result); } // Allocates enough memory for the return value and retrieves it byte[] output = new byte[returnValueSize.ToUInt32()]; result = DevicesNativeApi.GetDeviceInformation(Handle, deviceInformation, new UIntPtr((uint)output.Length), output, out returnValueSize); if (result != Result.Success) { throw new OpenClException("The device information could not be retrieved.", result); } // Returns the output return(InteropConverter.To <T>(output)); }
/// <summary> /// Disposes of the resources that have been acquired by the command queue. /// </summary> /// <param name="disposing">Determines whether managed object or managed and unmanaged resources should be disposed of.</param> protected override void Dispose(bool disposing) { // Checks if the device has already been disposed of, if not, then the device is disposed of if (!this.IsDisposed) { DevicesNativeApi.ReleaseDevice(this.Handle); } // Makes sure that the base class can execute its dispose logic base.Dispose(disposing); }
/// <summary> /// Disposes of the resources that have been acquired by the command queue. /// </summary> /// <param name="disposing">Determines whether managed object or managed and unmanaged resources should be disposed of.</param> public override void Dispose() { // Checks if the device has already been disposed of, if not, then the device is disposed of if (!IsDisposed) { DevicesNativeApi.ReleaseDevice(Handle); } // Makes sure that the base class can execute its dispose logic base.Dispose(); }
public uint GetDeviceCount(DeviceType deviceType) { Result result = DevicesNativeApi.GetDeviceIds( Handle, (Interop.Devices.DeviceType)deviceType, 0, null, out uint numberOfAvailableDevices ); return(numberOfAvailableDevices); }
public static string GetAmdDeviceName(OpenCl.DotNetCore.Devices.Device device) { var deviceHandle = GetDeviceHandle(device); var deviceInformation = (OpenCl.DotNetCore.Interop.Devices.DeviceInformation)DeviceInformation.CL_DEVICE_BOARD_NAME_AMD; var nameBin = new byte[256]; var result = DevicesNativeApi.GetDeviceInformation(deviceHandle, deviceInformation, new UIntPtr(256), nameBin, out UIntPtr rVal); if (result != Result.Success) { throw new Exception($"The device information could not be retrieved. Error code: {result}."); } return(System.Text.Encoding.ASCII.GetString(nameBin).TrimEnd(char.MinValue)); }
public static ulong GetAvailableMemory(OpenCl.DotNetCore.Devices.Device device) { var deviceHandle = GetDeviceHandle(device); var deviceInformation = (OpenCl.DotNetCore.Interop.Devices.DeviceInformation)DeviceInformation.CL_DEVICE_GLOBAL_FREE_MEMORY_AMD; var output = new byte[8]; var result = DevicesNativeApi.GetDeviceInformation(deviceHandle, deviceInformation, new UIntPtr(8), output, out UIntPtr rVal); if (result != Result.Success) { throw new Exception($"The device information could not be retrieved. Error code: {result}."); } var memory = new ulong[1]; Buffer.BlockCopy(output, 0, memory, 0, 8); return(memory[0] * (ulong)Math.Pow(2, 10)); }
/// <summary> /// Provides a list of available OpenCL devices on the system /// </summary> /// <returns>A list of OpenCL devices</returns> public static List <ComputeDeviceDesc> GetDevices() { List <ComputeDeviceDesc> ret = new List <ComputeDeviceDesc>(); // Gets the number of available platforms uint numberOfAvailablePlatforms; Result result = PlatformsNativeApi.GetPlatformIds(0, null, out numberOfAvailablePlatforms); if (result != Result.Success) { throw new OpenClException("The number of platforms could not be queried.", result); } // Gets pointers to all the platforms IntPtr[] platformPointers = new IntPtr[numberOfAvailablePlatforms]; result = PlatformsNativeApi.GetPlatformIds(numberOfAvailablePlatforms, platformPointers, out numberOfAvailablePlatforms); if (result != Result.Success) { throw new OpenClException("The platforms could not be retrieved.", result); } // Converts the pointers to platform objects int platformId = 0; foreach (IntPtr platformPointer in platformPointers) { ++platformId; // Gets the number of available devices of the specified type uint numberOfAvailableDevices; Result result_d = DevicesNativeApi.GetDeviceIds(platformPointer, DeviceType.All, 0, null, out numberOfAvailableDevices); if (result_d != Result.Success) { throw new OpenClException("The number of available devices could not be queried.", result_d); } // Gets the pointers to the devices of the specified type IntPtr[] devicePointers = new IntPtr[numberOfAvailableDevices]; result_d = DevicesNativeApi.GetDeviceIds(platformPointer, DeviceType.All, numberOfAvailableDevices, devicePointers, out numberOfAvailableDevices); if (result_d != Result.Success) { throw new OpenClException("The devices could not be retrieved.", result_d); } // Converts the pointer to device objects int deviceId = 0; foreach (IntPtr devicePointer in devicePointers) { ++deviceId; OpenCLComputeDeviceDesc devDesc = new OpenCLComputeDeviceDesc(); devDesc.platform = platformPointer; devDesc.device = devicePointer; devDesc.platformId = platformId; devDesc.deviceId = deviceId; ret.Add(devDesc); } } return(ret); }