/// <summary> /// Resolves device information as typed structure value of type <typeparamref name="T"/> /// </summary> /// <typeparam name="T">The target type.</typeparam> /// <param name="device">The device.</param> /// <param name="type">The information type.</param> /// <returns>The resolved value.</returns> public static T GetDeviceInfo <T>(IntPtr device, CLDeviceInfoType type) where T : struct { CLException.ThrowIfFailed(GetDeviceInfo( device, type, out T value)); return(value); }
/// <summary> /// Resolves device information as typed structure value of type <typeparamref name="T"/> /// </summary> /// <typeparam name="T">The target type.</typeparam> /// <param name="device">The device.</param> /// <param name="type">The information type.</param> /// <param name="value">The resolved value.</param> /// <returns>The error code.</returns> public static CLError GetDeviceInfo <T>(IntPtr device, CLDeviceInfoType type, out T value) where T : struct { value = default; return(NativeMethods.GetDeviceInfo( device, type, new IntPtr(Interop.SizeOf <T>()), Unsafe.AsPointer(ref value), IntPtr.Zero)); }
/// <summary> /// Resolves device information as array of typed structure values of type /// <typeparamref name="T"/>. /// </summary> /// <typeparam name="T">The target type.</typeparam> /// <param name="device">The device.</param> /// <param name="type">The information type.</param> /// <param name="elements">The elements to fill.</param> /// <returns>The resolved value.</returns> public static void GetDeviceInfo <T>( IntPtr device, CLDeviceInfoType type, T[] elements) where T : unmanaged { fixed(T *ptr = &elements[0]) { CLException.ThrowIfFailed(NativeMethods.GetDeviceInfo( device, type, new IntPtr(Interop.SizeOf <T>() * elements.Length), ptr, IntPtr.Zero)); } }
/// <summary> /// Resolves device information as string value. /// </summary> /// <param name="device">The device.</param> /// <param name="type">The information type.</param> /// <returns>The resolved string value.</returns> public static string GetDeviceInfo(IntPtr device, CLDeviceInfoType type) { const int MaxStringLength = 8192; var stringValue = stackalloc sbyte[MaxStringLength]; var size = IntPtr.Zero; CLException.ThrowIfFailed(NativeMethods.GetDeviceInfo( device, type, new IntPtr(MaxStringLength), stringValue, new IntPtr(&size))); int intSize = size.ToInt32(); return(intSize > 0 && intSize < MaxStringLength ? new string(stringValue, 0, intSize - 1) : string.Empty); }
/// <summary> /// Resolves device information as array of typed structure values of type <typeparamref name="T"/> /// </summary> /// <typeparam name="T">The target type.</typeparam> /// <param name="device">The device.</param> /// <param name="type">The information type.</param> /// <param name="elements">The elements to fill.</param> /// <returns>The resolved value.</returns> public static void GetDeviceInfo <T>(IntPtr device, CLDeviceInfoType type, T[] elements) where T : struct { var handle = GCHandle.Alloc(elements, GCHandleType.Pinned); try { CLException.ThrowIfFailed(NativeMethods.GetDeviceInfo( device, type, new IntPtr(Interop.SizeOf <T>() * elements.Length), handle.AddrOfPinnedObject().ToPointer(), IntPtr.Zero)); } finally { handle.Free(); } }
public static extern CLError GetDeviceInfo( [In] IntPtr deviceId, [In] CLDeviceInfoType deviceInfoType, [In] IntPtr maxSize, [Out] void *value, [Out] IntPtr size);
/// <summary> /// Resolves device information as typed structure value of type /// <typeparamref name="T"/>. /// </summary> /// <typeparam name="T">The target type.</typeparam> /// <param name="type">The information type.</param> /// <returns>The resolved value.</returns> public T GetDeviceInfo <T>(CLDeviceInfoType type) where T : unmanaged => CLAPI.GetDeviceInfo <T>(DeviceId, type);
/// <summary> /// Resolves device information as typed structure value of type /// <typeparamref name="T"/>. /// </summary> /// <typeparam name="T">The target type.</typeparam> /// <param name="type">The information type.</param> /// <param name="value">The resolved value.</param> /// <returns>The error code.</returns> public CLError GetDeviceInfo <T>(CLDeviceInfoType type, out T value) where T : unmanaged => CLAPI.GetDeviceInfo(DeviceId, type, out value);