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> /// 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)); }
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)); }