Class NvmlFunctions

java.lang.Object
oshi.ffm.ForeignFunctions
oshi.ffm.common.NvmlFunctions

public final class NvmlFunctions extends ForeignFunctions
FFM bindings for the NVIDIA Management Library (NVML).
  • Field Details

    • NVML_SUCCESS

      public static final int NVML_SUCCESS
      Successful return code.
      See Also:
    • NVML_TEMPERATURE_GPU

      public static final int NVML_TEMPERATURE_GPU
      GPU temperature sensor type.
      See Also:
    • NVML_CLOCK_GRAPHICS

      public static final int NVML_CLOCK_GRAPHICS
      Graphics clock domain.
      See Also:
    • NVML_CLOCK_MEM

      public static final int NVML_CLOCK_MEM
      Memory clock domain.
      See Also:
    • NVML_DEVICE_NAME_BUFFER_SIZE

      public static final int NVML_DEVICE_NAME_BUFFER_SIZE
      Buffer size for device name queries.
      See Also:
    • UTILIZATION_LAYOUT

      public static final StructLayout UTILIZATION_LAYOUT
      Layout for nvmlUtilization_t struct.
    • MEMORY_LAYOUT

      public static final StructLayout MEMORY_LAYOUT
      Layout for nvmlMemory_t struct.
    • PCI_INFO_LAYOUT

      public static final StructLayout PCI_INFO_LAYOUT
      Layout for nvmlPciInfo_t struct.
  • Method Details

    • isAvailable

      public static boolean isAvailable()
      Returns whether the NVML native library was successfully loaded.
      Returns:
      true if the NVML library is available
    • init

      public static int init()
      Calls nvmlInit_v2.
      Returns:
      NVML return code
    • shutdown

      public static int shutdown()
      Calls nvmlShutdown.
      Returns:
      NVML return code
    • deviceGetCount

      public static int deviceGetCount(MemorySegment countSeg)
      Gets the device count.
      Parameters:
      countSeg - pointer to int to receive count
      Returns:
      NVML return code
    • deviceGetHandleByIndex

      public static int deviceGetHandleByIndex(int index, MemorySegment handleSeg)
      Gets a device handle by index.
      Parameters:
      index - device index
      handleSeg - pointer to receive device handle
      Returns:
      NVML return code
    • deviceGetName

      public static int deviceGetName(MemorySegment device, MemorySegment nameSeg, int length)
      Gets the device name.
      Parameters:
      device - device handle
      nameSeg - buffer to receive name
      length - buffer length
      Returns:
      NVML return code
    • deviceGetPciInfo

      public static int deviceGetPciInfo(MemorySegment device, MemorySegment pciSeg)
      Gets PCI info for a device.
      Parameters:
      device - device handle
      pciSeg - nvmlPciInfo_t struct to fill
      Returns:
      NVML return code
    • deviceGetUtilizationRates

      public static int deviceGetUtilizationRates(MemorySegment device, MemorySegment utilSeg)
      Gets utilization rates for a device.
      Parameters:
      device - device handle
      utilSeg - nvmlUtilization_t struct to fill
      Returns:
      NVML return code
    • deviceGetMemoryInfo

      public static int deviceGetMemoryInfo(MemorySegment device, MemorySegment memSeg)
      Gets memory info for a device.
      Parameters:
      device - device handle
      memSeg - nvmlMemory_t struct to fill
      Returns:
      NVML return code
    • deviceGetTemperature

      public static int deviceGetTemperature(MemorySegment device, int sensorType, MemorySegment tempSeg)
      Gets temperature for a device.
      Parameters:
      device - device handle
      sensorType - sensor type constant
      tempSeg - pointer to int to receive temperature
      Returns:
      NVML return code
    • deviceGetPowerUsage

      public static int deviceGetPowerUsage(MemorySegment device, MemorySegment powerSeg)
      Gets power usage for a device.
      Parameters:
      device - device handle
      powerSeg - pointer to int to receive power in milliwatts
      Returns:
      NVML return code
    • deviceGetClockInfo

      public static int deviceGetClockInfo(MemorySegment device, int clockType, MemorySegment clockSeg)
      Gets clock info for a device.
      Parameters:
      device - device handle
      clockType - clock type constant
      clockSeg - pointer to int to receive clock in MHz
      Returns:
      NVML return code
    • deviceGetFanSpeed

      public static int deviceGetFanSpeed(MemorySegment device, MemorySegment speedSeg)
      Gets fan speed for a device.
      Parameters:
      device - device handle
      speedSeg - pointer to int to receive fan speed percentage
      Returns:
      NVML return code
    • readString

      public static String readString(MemorySegment seg, long offset, int maxLen)
      Reads a null-terminated string from a byte sequence within a struct segment.
      Parameters:
      seg - the struct segment
      offset - byte offset of the char array field
      maxLen - maximum length of the char array
      Returns:
      the string, or empty if null/empty