text:
# Automatically-generated headers for nvml
#
# DO NOT EDIT THIS FILE DIRECTLY.

# Julia wrapper for header: nvml.h
# Automatically generated using Clang.jl

@checked function nvmlInit_v2()
    @runtime_ccall((:nvmlInit_v2, libnvml()), nvmlReturn_t, ())
end

@checked function nvmlInitWithFlags(flags)
    @runtime_ccall((:nvmlInitWithFlags, libnvml()), nvmlReturn_t,
                   (UInt32,),
                   flags)
end

@checked function nvmlShutdown()
    @runtime_ccall((:nvmlShutdown, libnvml()), nvmlReturn_t, ())
end

function nvmlErrorString(result)
    @runtime_ccall((:nvmlErrorString, libnvml()), Cstring,
                   (nvmlReturn_t,),
                   result)
end

@checked function nvmlSystemGetDriverVersion(version, length)
    initialize_api()
    @runtime_ccall((:nvmlSystemGetDriverVersion, libnvml()), nvmlReturn_t,
                   (Cstring, UInt32),
                   version, length)
end

@checked function nvmlSystemGetNVMLVersion(version, length)
    initialize_api()
    @runtime_ccall((:nvmlSystemGetNVMLVersion, libnvml()), nvmlReturn_t,
                   (Cstring, UInt32),
                   version, length)
end

@checked function nvmlSystemGetCudaDriverVersion(cudaDriverVersion)
    initialize_api()
    @runtime_ccall((:nvmlSystemGetCudaDriverVersion, libnvml()), nvmlReturn_t,
                   (Ptr{Cint},),
                   cudaDriverVersion)
end

@checked function nvmlSystemGetCudaDriverVersion_v2(cudaDriverVersion)
    initialize_api()
    @runtime_ccall((:nvmlSystemGetCudaDriverVersion_v2, libnvml()), nvmlReturn_t,
                   (Ptr{Cint},),
                   cudaDriverVersion)
end

@checked function nvmlSystemGetProcessName(pid, name, length)
    initialize_api()
    @runtime_ccall((:nvmlSystemGetProcessName, libnvml()), nvmlReturn_t,
                   (UInt32, Cstring, UInt32),
                   pid, name, length)
end

@checked function nvmlUnitGetCount(unitCount)
    initialize_api()
    @runtime_ccall((:nvmlUnitGetCount, libnvml()), nvmlReturn_t,
                   (Ptr{UInt32},),
                   unitCount)
end

@checked function nvmlUnitGetHandleByIndex(index, unit)
    initialize_api()
    @runtime_ccall((:nvmlUnitGetHandleByIndex, libnvml()), nvmlReturn_t,
                   (UInt32, Ptr{nvmlUnit_t}),
                   index, unit)
end

@checked function nvmlUnitGetUnitInfo(unit, info)
    initialize_api()
    @runtime_ccall((:nvmlUnitGetUnitInfo, libnvml()), nvmlReturn_t,
                   (nvmlUnit_t, Ptr{nvmlUnitInfo_t}),
                   unit, info)
end

@checked function nvmlUnitGetLedState(unit, state)
    initialize_api()
    @runtime_ccall((:nvmlUnitGetLedState, libnvml()), nvmlReturn_t,
                   (nvmlUnit_t, Ptr{nvmlLedState_t}),
                   unit, state)
end

@checked function nvmlUnitGetPsuInfo(unit, psu)
    initialize_api()
    @runtime_ccall((:nvmlUnitGetPsuInfo, libnvml()), nvmlReturn_t,
                   (nvmlUnit_t, Ptr{nvmlPSUInfo_t}),
                   unit, psu)
end

@checked function nvmlUnitGetTemperature(unit, type, temp)
    initialize_api()
    @runtime_ccall((:nvmlUnitGetTemperature, libnvml()), nvmlReturn_t,
                   (nvmlUnit_t, UInt32, Ptr{UInt32}),
                   unit, type, temp)
end

@checked function nvmlUnitGetFanSpeedInfo(unit, fanSpeeds)
    initialize_api()
    @runtime_ccall((:nvmlUnitGetFanSpeedInfo, libnvml()), nvmlReturn_t,
                   (nvmlUnit_t, Ptr{nvmlUnitFanSpeeds_t}),
                   unit, fanSpeeds)
end

@checked function nvmlUnitGetDevices(unit, deviceCount, devices)
    initialize_api()
    @runtime_ccall((:nvmlUnitGetDevices, libnvml()), nvmlReturn_t,
                   (nvmlUnit_t, Ptr{UInt32}, Ptr{nvmlDevice_t}),
                   unit, deviceCount, devices)
end

@checked function nvmlSystemGetHicVersion(hwbcCount, hwbcEntries)
    initialize_api()
    @runtime_ccall((:nvmlSystemGetHicVersion, libnvml()), nvmlReturn_t,
                   (Ptr{UInt32}, Ptr{nvmlHwbcEntry_t}),
                   hwbcCount, hwbcEntries)
end

@checked function nvmlDeviceGetCount_v2(deviceCount)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetCount_v2, libnvml()), nvmlReturn_t,
                   (Ptr{UInt32},),
                   deviceCount)
end

@checked function nvmlDeviceGetAttributes(device, attributes)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetAttributes, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlDeviceAttributes_t}),
                   device, attributes)
end

@checked function nvmlDeviceGetHandleByIndex_v2(index, device)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetHandleByIndex_v2, libnvml()), nvmlReturn_t,
                   (UInt32, Ptr{nvmlDevice_t}),
                   index, device)
end

@checked function nvmlDeviceGetHandleBySerial(serial, device)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetHandleBySerial, libnvml()), nvmlReturn_t,
                   (Cstring, Ptr{nvmlDevice_t}),
                   serial, device)
end

@checked function nvmlDeviceGetHandleByUUID(uuid, device)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetHandleByUUID, libnvml()), nvmlReturn_t,
                   (Cstring, Ptr{nvmlDevice_t}),
                   uuid, device)
end

@checked function nvmlDeviceGetHandleByPciBusId_v2(pciBusId, device)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetHandleByPciBusId_v2, libnvml()), nvmlReturn_t,
                   (Cstring, Ptr{nvmlDevice_t}),
                   pciBusId, device)
end

@checked function nvmlDeviceGetName(device, name, length)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetName, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Cstring, UInt32),
                   device, name, length)
end

@checked function nvmlDeviceGetBrand(device, type)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetBrand, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlBrandType_t}),
                   device, type)
end

@checked function nvmlDeviceGetIndex(device, index)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetIndex, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, index)
end

@checked function nvmlDeviceGetSerial(device, serial, length)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetSerial, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Cstring, UInt32),
                   device, serial, length)
end

@checked function nvmlDeviceGetMemoryAffinity(device, nodeSetSize, nodeSet, scope)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetMemoryAffinity, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{Culong}, nvmlAffinityScope_t),
                   device, nodeSetSize, nodeSet, scope)
end

@checked function nvmlDeviceGetCpuAffinityWithinScope(device, cpuSetSize, cpuSet, scope)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetCpuAffinityWithinScope, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{Culong}, nvmlAffinityScope_t),
                   device, cpuSetSize, cpuSet, scope)
end

@checked function nvmlDeviceGetCpuAffinity(device, cpuSetSize, cpuSet)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetCpuAffinity, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{Culong}),
                   device, cpuSetSize, cpuSet)
end

@checked function nvmlDeviceSetCpuAffinity(device)
    initialize_api()
    @runtime_ccall((:nvmlDeviceSetCpuAffinity, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t,),
                   device)
end

@checked function nvmlDeviceClearCpuAffinity(device)
    initialize_api()
    @runtime_ccall((:nvmlDeviceClearCpuAffinity, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t,),
                   device)
end

@checked function nvmlDeviceGetTopologyCommonAncestor(device1, device2, pathInfo)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetTopologyCommonAncestor, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlDevice_t, Ptr{nvmlGpuTopologyLevel_t}),
                   device1, device2, pathInfo)
end

@checked function nvmlDeviceGetTopologyNearestGpus(device, level, count, deviceArray)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetTopologyNearestGpus, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlGpuTopologyLevel_t, Ptr{UInt32}, Ptr{nvmlDevice_t}),
                   device, level, count, deviceArray)
end

@checked function nvmlSystemGetTopologyGpuSet(cpuNumber, count, deviceArray)
    initialize_api()
    @runtime_ccall((:nvmlSystemGetTopologyGpuSet, libnvml()), nvmlReturn_t,
                   (UInt32, Ptr{UInt32}, Ptr{nvmlDevice_t}),
                   cpuNumber, count, deviceArray)
end

@checked function nvmlDeviceGetP2PStatus(device1, device2, p2pIndex, p2pStatus)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetP2PStatus, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlDevice_t, nvmlGpuP2PCapsIndex_t,
                    Ptr{nvmlGpuP2PStatus_t}),
                   device1, device2, p2pIndex, p2pStatus)
end

@checked function nvmlDeviceGetUUID(device, uuid, length)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetUUID, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Cstring, UInt32),
                   device, uuid, length)
end

@checked function nvmlVgpuInstanceGetMdevUUID(vgpuInstance, mdevUuid, size)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetMdevUUID, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Cstring, UInt32),
                   vgpuInstance, mdevUuid, size)
end

@checked function nvmlDeviceGetMinorNumber(device, minorNumber)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetMinorNumber, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, minorNumber)
end

@checked function nvmlDeviceGetBoardPartNumber(device, partNumber, length)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetBoardPartNumber, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Cstring, UInt32),
                   device, partNumber, length)
end

@checked function nvmlDeviceGetInforomVersion(device, object, version, length)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetInforomVersion, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlInforomObject_t, Cstring, UInt32),
                   device, object, version, length)
end

@checked function nvmlDeviceGetInforomImageVersion(device, version, length)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetInforomImageVersion, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Cstring, UInt32),
                   device, version, length)
end

@checked function nvmlDeviceGetInforomConfigurationChecksum(device, checksum)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetInforomConfigurationChecksum, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, checksum)
end

@checked function nvmlDeviceValidateInforom(device)
    initialize_api()
    @runtime_ccall((:nvmlDeviceValidateInforom, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t,),
                   device)
end

@checked function nvmlDeviceGetDisplayMode(device, display)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetDisplayMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlEnableState_t}),
                   device, display)
end

@checked function nvmlDeviceGetDisplayActive(device, isActive)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetDisplayActive, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlEnableState_t}),
                   device, isActive)
end

@checked function nvmlDeviceGetPersistenceMode(device, mode)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetPersistenceMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlEnableState_t}),
                   device, mode)
end

@checked function nvmlDeviceGetPciInfo_v3(device, pci)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetPciInfo_v3, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlPciInfo_t}),
                   device, pci)
end

@checked function nvmlDeviceGetMaxPcieLinkGeneration(device, maxLinkGen)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetMaxPcieLinkGeneration, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, maxLinkGen)
end

@checked function nvmlDeviceGetMaxPcieLinkWidth(device, maxLinkWidth)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetMaxPcieLinkWidth, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, maxLinkWidth)
end

@checked function nvmlDeviceGetCurrPcieLinkGeneration(device, currLinkGen)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetCurrPcieLinkGeneration, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, currLinkGen)
end

@checked function nvmlDeviceGetCurrPcieLinkWidth(device, currLinkWidth)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetCurrPcieLinkWidth, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, currLinkWidth)
end

@checked function nvmlDeviceGetPcieThroughput(device, counter, value)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetPcieThroughput, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlPcieUtilCounter_t, Ptr{UInt32}),
                   device, counter, value)
end

@checked function nvmlDeviceGetPcieReplayCounter(device, value)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetPcieReplayCounter, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, value)
end

@checked function nvmlDeviceGetClockInfo(device, type, clock)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetClockInfo, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlClockType_t, Ptr{UInt32}),
                   device, type, clock)
end

@checked function nvmlDeviceGetMaxClockInfo(device, type, clock)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetMaxClockInfo, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlClockType_t, Ptr{UInt32}),
                   device, type, clock)
end

@checked function nvmlDeviceGetApplicationsClock(device, clockType, clockMHz)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetApplicationsClock, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlClockType_t, Ptr{UInt32}),
                   device, clockType, clockMHz)
end

@checked function nvmlDeviceGetDefaultApplicationsClock(device, clockType, clockMHz)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetDefaultApplicationsClock, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlClockType_t, Ptr{UInt32}),
                   device, clockType, clockMHz)
end

@checked function nvmlDeviceResetApplicationsClocks(device)
    initialize_api()
    @runtime_ccall((:nvmlDeviceResetApplicationsClocks, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t,),
                   device)
end

@checked function nvmlDeviceGetClock(device, clockType, clockId, clockMHz)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetClock, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlClockType_t, nvmlClockId_t, Ptr{UInt32}),
                   device, clockType, clockId, clockMHz)
end

@checked function nvmlDeviceGetMaxCustomerBoostClock(device, clockType, clockMHz)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetMaxCustomerBoostClock, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlClockType_t, Ptr{UInt32}),
                   device, clockType, clockMHz)
end

@checked function nvmlDeviceGetSupportedMemoryClocks(device, count, clocksMHz)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetSupportedMemoryClocks, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}, Ptr{UInt32}),
                   device, count, clocksMHz)
end

@checked function nvmlDeviceGetSupportedGraphicsClocks(device, memoryClockMHz, count,
                                                       clocksMHz)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetSupportedGraphicsClocks, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{UInt32}, Ptr{UInt32}),
                   device, memoryClockMHz, count, clocksMHz)
end

@checked function nvmlDeviceGetAutoBoostedClocksEnabled(device, isEnabled, defaultIsEnabled)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetAutoBoostedClocksEnabled, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlEnableState_t}, Ptr{nvmlEnableState_t}),
                   device, isEnabled, defaultIsEnabled)
end

@checked function nvmlDeviceSetAutoBoostedClocksEnabled(device, enabled)
    initialize_api()
    @runtime_ccall((:nvmlDeviceSetAutoBoostedClocksEnabled, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlEnableState_t),
                   device, enabled)
end

@checked function nvmlDeviceSetDefaultAutoBoostedClocksEnabled(device, enabled, flags)
    initialize_api()
    @runtime_ccall((:nvmlDeviceSetDefaultAutoBoostedClocksEnabled, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlEnableState_t, UInt32),
                   device, enabled, flags)
end

@checked function nvmlDeviceGetFanSpeed(device, speed)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetFanSpeed, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, speed)
end

@checked function nvmlDeviceGetFanSpeed_v2(device, fan, speed)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetFanSpeed_v2, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{UInt32}),
                   device, fan, speed)
end

@checked function nvmlDeviceGetTemperature(device, sensorType, temp)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetTemperature, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlTemperatureSensors_t, Ptr{UInt32}),
                   device, sensorType, temp)
end

@checked function nvmlDeviceGetTemperatureThreshold(device, thresholdType, temp)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetTemperatureThreshold, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlTemperatureThresholds_t, Ptr{UInt32}),
                   device, thresholdType, temp)
end

@checked function nvmlDeviceGetPerformanceState(device, pState)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetPerformanceState, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlPstates_t}),
                   device, pState)
end

@checked function nvmlDeviceGetCurrentClocksThrottleReasons(device, clocksThrottleReasons)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetCurrentClocksThrottleReasons, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{Culonglong}),
                   device, clocksThrottleReasons)
end

@checked function nvmlDeviceGetSupportedClocksThrottleReasons(device,
                                                              supportedClocksThrottleReasons)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetSupportedClocksThrottleReasons, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{Culonglong}),
                   device, supportedClocksThrottleReasons)
end

@checked function nvmlDeviceGetPowerState(device, pState)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetPowerState, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlPstates_t}),
                   device, pState)
end

@checked function nvmlDeviceGetPowerManagementMode(device, mode)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetPowerManagementMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlEnableState_t}),
                   device, mode)
end

@checked function nvmlDeviceGetPowerManagementLimit(device, limit)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetPowerManagementLimit, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, limit)
end

@checked function nvmlDeviceGetPowerManagementLimitConstraints(device, minLimit, maxLimit)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetPowerManagementLimitConstraints, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}, Ptr{UInt32}),
                   device, minLimit, maxLimit)
end

@checked function nvmlDeviceGetPowerManagementDefaultLimit(device, defaultLimit)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetPowerManagementDefaultLimit, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, defaultLimit)
end

@checked function nvmlDeviceGetPowerUsage(device, power)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetPowerUsage, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, power)
end

@checked function nvmlDeviceGetTotalEnergyConsumption(device, energy)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetTotalEnergyConsumption, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{Culonglong}),
                   device, energy)
end

@checked function nvmlDeviceGetEnforcedPowerLimit(device, limit)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetEnforcedPowerLimit, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, limit)
end

@checked function nvmlDeviceGetGpuOperationMode(device, current, pending)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetGpuOperationMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlGpuOperationMode_t}, Ptr{nvmlGpuOperationMode_t}),
                   device, current, pending)
end

@checked function nvmlDeviceGetMemoryInfo(device, memory)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetMemoryInfo, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlMemory_t}),
                   device, memory)
end

@checked function nvmlDeviceGetComputeMode(device, mode)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetComputeMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlComputeMode_t}),
                   device, mode)
end

@checked function nvmlDeviceGetCudaComputeCapability(device, major, minor)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetCudaComputeCapability, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{Cint}, Ptr{Cint}),
                   device, major, minor)
end

@checked function nvmlDeviceGetEccMode(device, current, pending)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetEccMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlEnableState_t}, Ptr{nvmlEnableState_t}),
                   device, current, pending)
end

@checked function nvmlDeviceGetBoardId(device, boardId)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetBoardId, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, boardId)
end

@checked function nvmlDeviceGetMultiGpuBoard(device, multiGpuBool)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetMultiGpuBoard, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, multiGpuBool)
end

@checked function nvmlDeviceGetTotalEccErrors(device, errorType, counterType, eccCounts)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetTotalEccErrors, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlMemoryErrorType_t, nvmlEccCounterType_t,
                    Ptr{Culonglong}),
                   device, errorType, counterType, eccCounts)
end

@checked function nvmlDeviceGetDetailedEccErrors(device, errorType, counterType, eccCounts)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetDetailedEccErrors, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlMemoryErrorType_t, nvmlEccCounterType_t,
                    Ptr{nvmlEccErrorCounts_t}),
                   device, errorType, counterType, eccCounts)
end

@checked function nvmlDeviceGetMemoryErrorCounter(device, errorType, counterType,
                                                  locationType, count)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetMemoryErrorCounter, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlMemoryErrorType_t, nvmlEccCounterType_t,
                    nvmlMemoryLocation_t, Ptr{Culonglong}),
                   device, errorType, counterType, locationType, count)
end

@checked function nvmlDeviceGetUtilizationRates(device, utilization)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetUtilizationRates, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlUtilization_t}),
                   device, utilization)
end

@checked function nvmlDeviceGetEncoderUtilization(device, utilization, samplingPeriodUs)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetEncoderUtilization, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}, Ptr{UInt32}),
                   device, utilization, samplingPeriodUs)
end

@checked function nvmlDeviceGetEncoderCapacity(device, encoderQueryType, encoderCapacity)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetEncoderCapacity, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlEncoderType_t, Ptr{UInt32}),
                   device, encoderQueryType, encoderCapacity)
end

@checked function nvmlDeviceGetEncoderStats(device, sessionCount, averageFps, averageLatency)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetEncoderStats, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}, Ptr{UInt32}, Ptr{UInt32}),
                   device, sessionCount, averageFps, averageLatency)
end

@checked function nvmlDeviceGetEncoderSessions(device, sessionCount, sessionInfos)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetEncoderSessions, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}, Ptr{nvmlEncoderSessionInfo_t}),
                   device, sessionCount, sessionInfos)
end

@checked function nvmlDeviceGetDecoderUtilization(device, utilization, samplingPeriodUs)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetDecoderUtilization, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}, Ptr{UInt32}),
                   device, utilization, samplingPeriodUs)
end

@checked function nvmlDeviceGetFBCStats(device, fbcStats)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetFBCStats, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlFBCStats_t}),
                   device, fbcStats)
end

@checked function nvmlDeviceGetFBCSessions(device, sessionCount, sessionInfo)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetFBCSessions, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}, Ptr{nvmlFBCSessionInfo_t}),
                   device, sessionCount, sessionInfo)
end

@checked function nvmlDeviceGetDriverModel(device, current, pending)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetDriverModel, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlDriverModel_t}, Ptr{nvmlDriverModel_t}),
                   device, current, pending)
end

@checked function nvmlDeviceGetVbiosVersion(device, version, length)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetVbiosVersion, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Cstring, UInt32),
                   device, version, length)
end

@checked function nvmlDeviceGetBridgeChipInfo(device, bridgeHierarchy)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetBridgeChipInfo, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlBridgeChipHierarchy_t}),
                   device, bridgeHierarchy)
end

@checked function nvmlDeviceGetComputeRunningProcesses(device, infoCount, infos)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetComputeRunningProcesses, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}, Ptr{nvmlProcessInfo_t}),
                   device, infoCount, infos)
end

@checked function nvmlDeviceGetGraphicsRunningProcesses(device, infoCount, infos)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetGraphicsRunningProcesses, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}, Ptr{nvmlProcessInfo_t}),
                   device, infoCount, infos)
end

@checked function nvmlDeviceOnSameBoard(device1, device2, onSameBoard)
    initialize_api()
    @runtime_ccall((:nvmlDeviceOnSameBoard, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlDevice_t, Ptr{Cint}),
                   device1, device2, onSameBoard)
end

@checked function nvmlDeviceGetAPIRestriction(device, apiType, isRestricted)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetAPIRestriction, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlRestrictedAPI_t, Ptr{nvmlEnableState_t}),
                   device, apiType, isRestricted)
end

@checked function nvmlDeviceGetSamples(device, type, lastSeenTimeStamp, sampleValType,
                                       sampleCount, samples)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetSamples, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlSamplingType_t, Culonglong, Ptr{nvmlValueType_t},
                    Ptr{UInt32}, Ptr{nvmlSample_t}),
                   device, type, lastSeenTimeStamp, sampleValType, sampleCount, samples)
end

@checked function nvmlDeviceGetBAR1MemoryInfo(device, bar1Memory)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetBAR1MemoryInfo, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlBAR1Memory_t}),
                   device, bar1Memory)
end

@checked function nvmlDeviceGetViolationStatus(device, perfPolicyType, violTime)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetViolationStatus, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlPerfPolicyType_t, Ptr{nvmlViolationTime_t}),
                   device, perfPolicyType, violTime)
end

@checked function nvmlDeviceGetAccountingMode(device, mode)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetAccountingMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlEnableState_t}),
                   device, mode)
end

@checked function nvmlDeviceGetAccountingStats(device, pid, stats)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetAccountingStats, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{nvmlAccountingStats_t}),
                   device, pid, stats)
end

@checked function nvmlDeviceGetAccountingPids(device, count, pids)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetAccountingPids, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}, Ptr{UInt32}),
                   device, count, pids)
end

@checked function nvmlDeviceGetAccountingBufferSize(device, bufferSize)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetAccountingBufferSize, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, bufferSize)
end

@checked function nvmlDeviceGetRetiredPages(device, cause, pageCount, addresses)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetRetiredPages, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlPageRetirementCause_t, Ptr{UInt32}, Ptr{Culonglong}),
                   device, cause, pageCount, addresses)
end

@checked function nvmlDeviceGetRetiredPages_v2(device, cause, pageCount, addresses,
                                               timestamps)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetRetiredPages_v2, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlPageRetirementCause_t, Ptr{UInt32}, Ptr{Culonglong},
                    Ptr{Culonglong}),
                   device, cause, pageCount, addresses, timestamps)
end

@checked function nvmlDeviceGetRetiredPagesPendingStatus(device, isPending)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetRetiredPagesPendingStatus, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlEnableState_t}),
                   device, isPending)
end

@checked function nvmlDeviceGetRemappedRows(device, corrRows, uncRows, isPending,
                                            failureOccurred)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetRemappedRows, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}, Ptr{UInt32}, Ptr{UInt32}, Ptr{UInt32}),
                   device, corrRows, uncRows, isPending, failureOccurred)
end

@checked function nvmlDeviceGetArchitecture(device, arch)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetArchitecture, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlDeviceArchitecture_t}),
                   device, arch)
end

@checked function nvmlUnitSetLedState(unit, color)
    initialize_api()
    @runtime_ccall((:nvmlUnitSetLedState, libnvml()), nvmlReturn_t,
                   (nvmlUnit_t, nvmlLedColor_t),
                   unit, color)
end

@checked function nvmlDeviceSetPersistenceMode(device, mode)
    initialize_api()
    @runtime_ccall((:nvmlDeviceSetPersistenceMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlEnableState_t),
                   device, mode)
end

@checked function nvmlDeviceSetComputeMode(device, mode)
    initialize_api()
    @runtime_ccall((:nvmlDeviceSetComputeMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlComputeMode_t),
                   device, mode)
end

@checked function nvmlDeviceSetEccMode(device, ecc)
    initialize_api()
    @runtime_ccall((:nvmlDeviceSetEccMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlEnableState_t),
                   device, ecc)
end

@checked function nvmlDeviceClearEccErrorCounts(device, counterType)
    initialize_api()
    @runtime_ccall((:nvmlDeviceClearEccErrorCounts, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlEccCounterType_t),
                   device, counterType)
end

@checked function nvmlDeviceSetDriverModel(device, driverModel, flags)
    initialize_api()
    @runtime_ccall((:nvmlDeviceSetDriverModel, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlDriverModel_t, UInt32),
                   device, driverModel, flags)
end

@checked function nvmlDeviceSetGpuLockedClocks(device, minGpuClockMHz, maxGpuClockMHz)
    initialize_api()
    @runtime_ccall((:nvmlDeviceSetGpuLockedClocks, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, UInt32),
                   device, minGpuClockMHz, maxGpuClockMHz)
end

@checked function nvmlDeviceResetGpuLockedClocks(device)
    initialize_api()
    @runtime_ccall((:nvmlDeviceResetGpuLockedClocks, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t,),
                   device)
end

@checked function nvmlDeviceSetApplicationsClocks(device, memClockMHz, graphicsClockMHz)
    initialize_api()
    @runtime_ccall((:nvmlDeviceSetApplicationsClocks, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, UInt32),
                   device, memClockMHz, graphicsClockMHz)
end

@checked function nvmlDeviceSetPowerManagementLimit(device, limit)
    initialize_api()
    @runtime_ccall((:nvmlDeviceSetPowerManagementLimit, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32),
                   device, limit)
end

@checked function nvmlDeviceSetGpuOperationMode(device, mode)
    initialize_api()
    @runtime_ccall((:nvmlDeviceSetGpuOperationMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlGpuOperationMode_t),
                   device, mode)
end

@checked function nvmlDeviceSetAPIRestriction(device, apiType, isRestricted)
    initialize_api()
    @runtime_ccall((:nvmlDeviceSetAPIRestriction, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlRestrictedAPI_t, nvmlEnableState_t),
                   device, apiType, isRestricted)
end

@checked function nvmlDeviceSetAccountingMode(device, mode)
    initialize_api()
    @runtime_ccall((:nvmlDeviceSetAccountingMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlEnableState_t),
                   device, mode)
end

@checked function nvmlDeviceClearAccountingPids(device)
    initialize_api()
    @runtime_ccall((:nvmlDeviceClearAccountingPids, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t,),
                   device)
end

@checked function nvmlDeviceGetNvLinkState(device, link, isActive)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetNvLinkState, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{nvmlEnableState_t}),
                   device, link, isActive)
end

@checked function nvmlDeviceGetNvLinkVersion(device, link, version)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetNvLinkVersion, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{UInt32}),
                   device, link, version)
end

@checked function nvmlDeviceGetNvLinkCapability(device, link, capability, capResult)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetNvLinkCapability, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, nvmlNvLinkCapability_t, Ptr{UInt32}),
                   device, link, capability, capResult)
end

@checked function nvmlDeviceGetNvLinkRemotePciInfo_v2(device, link, pci)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetNvLinkRemotePciInfo_v2, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{nvmlPciInfo_t}),
                   device, link, pci)
end

@checked function nvmlDeviceGetNvLinkErrorCounter(device, link, counter, counterValue)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetNvLinkErrorCounter, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, nvmlNvLinkErrorCounter_t, Ptr{Culonglong}),
                   device, link, counter, counterValue)
end

@checked function nvmlDeviceResetNvLinkErrorCounters(device, link)
    initialize_api()
    @runtime_ccall((:nvmlDeviceResetNvLinkErrorCounters, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32),
                   device, link)
end

@checked function nvmlDeviceSetNvLinkUtilizationControl(device, link, counter, control,
                                                        reset)
    initialize_api()
    @runtime_ccall((:nvmlDeviceSetNvLinkUtilizationControl, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, UInt32, Ptr{nvmlNvLinkUtilizationControl_t},
                    UInt32),
                   device, link, counter, control, reset)
end

@checked function nvmlDeviceGetNvLinkUtilizationControl(device, link, counter, control)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetNvLinkUtilizationControl, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, UInt32, Ptr{nvmlNvLinkUtilizationControl_t}),
                   device, link, counter, control)
end

@checked function nvmlDeviceGetNvLinkUtilizationCounter(device, link, counter, rxcounter,
                                                        txcounter)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetNvLinkUtilizationCounter, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, UInt32, Ptr{Culonglong}, Ptr{Culonglong}),
                   device, link, counter, rxcounter, txcounter)
end

@checked function nvmlDeviceFreezeNvLinkUtilizationCounter(device, link, counter, freeze)
    initialize_api()
    @runtime_ccall((:nvmlDeviceFreezeNvLinkUtilizationCounter, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, UInt32, nvmlEnableState_t),
                   device, link, counter, freeze)
end

@checked function nvmlDeviceResetNvLinkUtilizationCounter(device, link, counter)
    initialize_api()
    @runtime_ccall((:nvmlDeviceResetNvLinkUtilizationCounter, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, UInt32),
                   device, link, counter)
end

@checked function nvmlEventSetCreate(set)
    initialize_api()
    @runtime_ccall((:nvmlEventSetCreate, libnvml()), nvmlReturn_t,
                   (Ptr{nvmlEventSet_t},),
                   set)
end

@checked function nvmlDeviceRegisterEvents(device, eventTypes, set)
    initialize_api()
    @runtime_ccall((:nvmlDeviceRegisterEvents, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Culonglong, nvmlEventSet_t),
                   device, eventTypes, set)
end

@checked function nvmlDeviceGetSupportedEventTypes(device, eventTypes)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetSupportedEventTypes, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{Culonglong}),
                   device, eventTypes)
end

@checked function nvmlEventSetWait_v2(set, data, timeoutms)
    initialize_api()
    @runtime_ccall((:nvmlEventSetWait_v2, libnvml()), nvmlReturn_t,
                   (nvmlEventSet_t, Ptr{nvmlEventData_t}, UInt32),
                   set, data, timeoutms)
end

@checked function nvmlEventSetFree(set)
    initialize_api()
    @runtime_ccall((:nvmlEventSetFree, libnvml()), nvmlReturn_t,
                   (nvmlEventSet_t,),
                   set)
end

@checked function nvmlDeviceModifyDrainState(pciInfo, newState)
    initialize_api()
    @runtime_ccall((:nvmlDeviceModifyDrainState, libnvml()), nvmlReturn_t,
                   (Ptr{nvmlPciInfo_t}, nvmlEnableState_t),
                   pciInfo, newState)
end

@checked function nvmlDeviceQueryDrainState(pciInfo, currentState)
    initialize_api()
    @runtime_ccall((:nvmlDeviceQueryDrainState, libnvml()), nvmlReturn_t,
                   (Ptr{nvmlPciInfo_t}, Ptr{nvmlEnableState_t}),
                   pciInfo, currentState)
end

@checked function nvmlDeviceRemoveGpu_v2(pciInfo, gpuState, linkState)
    initialize_api()
    @runtime_ccall((:nvmlDeviceRemoveGpu_v2, libnvml()), nvmlReturn_t,
                   (Ptr{nvmlPciInfo_t}, nvmlDetachGpuState_t, nvmlPcieLinkState_t),
                   pciInfo, gpuState, linkState)
end

@checked function nvmlDeviceDiscoverGpus(pciInfo)
    initialize_api()
    @runtime_ccall((:nvmlDeviceDiscoverGpus, libnvml()), nvmlReturn_t,
                   (Ptr{nvmlPciInfo_t},),
                   pciInfo)
end

@checked function nvmlDeviceGetFieldValues(device, valuesCount, values)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetFieldValues, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Cint, Ptr{nvmlFieldValue_t}),
                   device, valuesCount, values)
end

@checked function nvmlDeviceGetVirtualizationMode(device, pVirtualMode)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetVirtualizationMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlGpuVirtualizationMode_t}),
                   device, pVirtualMode)
end

@checked function nvmlDeviceGetHostVgpuMode(device, pHostVgpuMode)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetHostVgpuMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlHostVgpuMode_t}),
                   device, pHostVgpuMode)
end

@checked function nvmlDeviceSetVirtualizationMode(device, virtualMode)
    initialize_api()
    @runtime_ccall((:nvmlDeviceSetVirtualizationMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlGpuVirtualizationMode_t),
                   device, virtualMode)
end

@checked function nvmlDeviceGetGridLicensableFeatures_v3(device, pGridLicensableFeatures)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetGridLicensableFeatures_v3, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlGridLicensableFeatures_t}),
                   device, pGridLicensableFeatures)
end

@checked function nvmlDeviceGetProcessUtilization(device, utilization, processSamplesCount,
                                                  lastSeenTimeStamp)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetProcessUtilization, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlProcessUtilizationSample_t}, Ptr{UInt32},
                    Culonglong),
                   device, utilization, processSamplesCount, lastSeenTimeStamp)
end

@checked function nvmlDeviceGetSupportedVgpus(device, vgpuCount, vgpuTypeIds)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetSupportedVgpus, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}, Ptr{nvmlVgpuTypeId_t}),
                   device, vgpuCount, vgpuTypeIds)
end

@checked function nvmlDeviceGetCreatableVgpus(device, vgpuCount, vgpuTypeIds)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetCreatableVgpus, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}, Ptr{nvmlVgpuTypeId_t}),
                   device, vgpuCount, vgpuTypeIds)
end

@checked function nvmlVgpuTypeGetClass(vgpuTypeId, vgpuTypeClass, size)
    initialize_api()
    @runtime_ccall((:nvmlVgpuTypeGetClass, libnvml()), nvmlReturn_t,
                   (nvmlVgpuTypeId_t, Cstring, Ptr{UInt32}),
                   vgpuTypeId, vgpuTypeClass, size)
end

@checked function nvmlVgpuTypeGetName(vgpuTypeId, vgpuTypeName, size)
    initialize_api()
    @runtime_ccall((:nvmlVgpuTypeGetName, libnvml()), nvmlReturn_t,
                   (nvmlVgpuTypeId_t, Cstring, Ptr{UInt32}),
                   vgpuTypeId, vgpuTypeName, size)
end

@checked function nvmlVgpuTypeGetDeviceID(vgpuTypeId, deviceID, subsystemID)
    initialize_api()
    @runtime_ccall((:nvmlVgpuTypeGetDeviceID, libnvml()), nvmlReturn_t,
                   (nvmlVgpuTypeId_t, Ptr{Culonglong}, Ptr{Culonglong}),
                   vgpuTypeId, deviceID, subsystemID)
end

@checked function nvmlVgpuTypeGetFramebufferSize(vgpuTypeId, fbSize)
    initialize_api()
    @runtime_ccall((:nvmlVgpuTypeGetFramebufferSize, libnvml()), nvmlReturn_t,
                   (nvmlVgpuTypeId_t, Ptr{Culonglong}),
                   vgpuTypeId, fbSize)
end

@checked function nvmlVgpuTypeGetNumDisplayHeads(vgpuTypeId, numDisplayHeads)
    initialize_api()
    @runtime_ccall((:nvmlVgpuTypeGetNumDisplayHeads, libnvml()), nvmlReturn_t,
                   (nvmlVgpuTypeId_t, Ptr{UInt32}),
                   vgpuTypeId, numDisplayHeads)
end

@checked function nvmlVgpuTypeGetResolution(vgpuTypeId, displayIndex, xdim, ydim)
    initialize_api()
    @runtime_ccall((:nvmlVgpuTypeGetResolution, libnvml()), nvmlReturn_t,
                   (nvmlVgpuTypeId_t, UInt32, Ptr{UInt32}, Ptr{UInt32}),
                   vgpuTypeId, displayIndex, xdim, ydim)
end

@checked function nvmlVgpuTypeGetLicense(vgpuTypeId, vgpuTypeLicenseString, size)
    initialize_api()
    @runtime_ccall((:nvmlVgpuTypeGetLicense, libnvml()), nvmlReturn_t,
                   (nvmlVgpuTypeId_t, Cstring, UInt32),
                   vgpuTypeId, vgpuTypeLicenseString, size)
end

@checked function nvmlVgpuTypeGetFrameRateLimit(vgpuTypeId, frameRateLimit)
    initialize_api()
    @runtime_ccall((:nvmlVgpuTypeGetFrameRateLimit, libnvml()), nvmlReturn_t,
                   (nvmlVgpuTypeId_t, Ptr{UInt32}),
                   vgpuTypeId, frameRateLimit)
end

@checked function nvmlVgpuTypeGetMaxInstances(device, vgpuTypeId, vgpuInstanceCount)
    initialize_api()
    @runtime_ccall((:nvmlVgpuTypeGetMaxInstances, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, nvmlVgpuTypeId_t, Ptr{UInt32}),
                   device, vgpuTypeId, vgpuInstanceCount)
end

@checked function nvmlVgpuTypeGetMaxInstancesPerVm(vgpuTypeId, vgpuInstanceCountPerVm)
    initialize_api()
    @runtime_ccall((:nvmlVgpuTypeGetMaxInstancesPerVm, libnvml()), nvmlReturn_t,
                   (nvmlVgpuTypeId_t, Ptr{UInt32}),
                   vgpuTypeId, vgpuInstanceCountPerVm)
end

@checked function nvmlDeviceGetActiveVgpus(device, vgpuCount, vgpuInstances)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetActiveVgpus, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}, Ptr{nvmlVgpuInstance_t}),
                   device, vgpuCount, vgpuInstances)
end

@checked function nvmlVgpuInstanceGetVmID(vgpuInstance, vmId, size, vmIdType)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetVmID, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Cstring, UInt32, Ptr{nvmlVgpuVmIdType_t}),
                   vgpuInstance, vmId, size, vmIdType)
end

@checked function nvmlVgpuInstanceGetUUID(vgpuInstance, uuid, size)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetUUID, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Cstring, UInt32),
                   vgpuInstance, uuid, size)
end

@checked function nvmlVgpuInstanceGetVmDriverVersion(vgpuInstance, version, length)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetVmDriverVersion, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Cstring, UInt32),
                   vgpuInstance, version, length)
end

@checked function nvmlVgpuInstanceGetFbUsage(vgpuInstance, fbUsage)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetFbUsage, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Ptr{Culonglong}),
                   vgpuInstance, fbUsage)
end

@checked function nvmlVgpuInstanceGetLicenseStatus(vgpuInstance, licensed)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetLicenseStatus, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Ptr{UInt32}),
                   vgpuInstance, licensed)
end

@checked function nvmlVgpuInstanceGetType(vgpuInstance, vgpuTypeId)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetType, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Ptr{nvmlVgpuTypeId_t}),
                   vgpuInstance, vgpuTypeId)
end

@checked function nvmlVgpuInstanceGetFrameRateLimit(vgpuInstance, frameRateLimit)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetFrameRateLimit, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Ptr{UInt32}),
                   vgpuInstance, frameRateLimit)
end

@checked function nvmlVgpuInstanceGetEccMode(vgpuInstance, eccMode)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetEccMode, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Ptr{nvmlEnableState_t}),
                   vgpuInstance, eccMode)
end

@checked function nvmlVgpuInstanceGetEncoderCapacity(vgpuInstance, encoderCapacity)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetEncoderCapacity, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Ptr{UInt32}),
                   vgpuInstance, encoderCapacity)
end

@checked function nvmlVgpuInstanceSetEncoderCapacity(vgpuInstance, encoderCapacity)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceSetEncoderCapacity, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, UInt32),
                   vgpuInstance, encoderCapacity)
end

@checked function nvmlVgpuInstanceGetEncoderStats(vgpuInstance, sessionCount, averageFps,
                                                  averageLatency)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetEncoderStats, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Ptr{UInt32}, Ptr{UInt32}, Ptr{UInt32}),
                   vgpuInstance, sessionCount, averageFps, averageLatency)
end

@checked function nvmlVgpuInstanceGetEncoderSessions(vgpuInstance, sessionCount, sessionInfo)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetEncoderSessions, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Ptr{UInt32}, Ptr{nvmlEncoderSessionInfo_t}),
                   vgpuInstance, sessionCount, sessionInfo)
end

@checked function nvmlVgpuInstanceGetFBCStats(vgpuInstance, fbcStats)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetFBCStats, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Ptr{nvmlFBCStats_t}),
                   vgpuInstance, fbcStats)
end

@checked function nvmlVgpuInstanceGetFBCSessions(vgpuInstance, sessionCount, sessionInfo)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetFBCSessions, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Ptr{UInt32}, Ptr{nvmlFBCSessionInfo_t}),
                   vgpuInstance, sessionCount, sessionInfo)
end

@checked function nvmlVgpuInstanceGetMetadata(vgpuInstance, vgpuMetadata, bufferSize)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetMetadata, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Ptr{nvmlVgpuMetadata_t}, Ptr{UInt32}),
                   vgpuInstance, vgpuMetadata, bufferSize)
end

@checked function nvmlDeviceGetVgpuMetadata(device, pgpuMetadata, bufferSize)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetVgpuMetadata, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlVgpuPgpuMetadata_t}, Ptr{UInt32}),
                   device, pgpuMetadata, bufferSize)
end

@checked function nvmlGetVgpuCompatibility(vgpuMetadata, pgpuMetadata, compatibilityInfo)
    initialize_api()
    @runtime_ccall((:nvmlGetVgpuCompatibility, libnvml()), nvmlReturn_t,
                   (Ptr{nvmlVgpuMetadata_t}, Ptr{nvmlVgpuPgpuMetadata_t},
                    Ptr{nvmlVgpuPgpuCompatibility_t}),
                   vgpuMetadata, pgpuMetadata, compatibilityInfo)
end

@checked function nvmlDeviceGetPgpuMetadataString(device, pgpuMetadata, bufferSize)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetPgpuMetadataString, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Cstring, Ptr{UInt32}),
                   device, pgpuMetadata, bufferSize)
end

@checked function nvmlGetVgpuVersion(supported, current)
    initialize_api()
    @runtime_ccall((:nvmlGetVgpuVersion, libnvml()), nvmlReturn_t,
                   (Ptr{nvmlVgpuVersion_t}, Ptr{nvmlVgpuVersion_t}),
                   supported, current)
end

@checked function nvmlSetVgpuVersion(vgpuVersion)
    initialize_api()
    @runtime_ccall((:nvmlSetVgpuVersion, libnvml()), nvmlReturn_t,
                   (Ptr{nvmlVgpuVersion_t},),
                   vgpuVersion)
end

@checked function nvmlDeviceGetVgpuUtilization(device, lastSeenTimeStamp, sampleValType,
                                               vgpuInstanceSamplesCount, utilizationSamples)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetVgpuUtilization, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Culonglong, Ptr{nvmlValueType_t}, Ptr{UInt32},
                    Ptr{nvmlVgpuInstanceUtilizationSample_t}),
                   device, lastSeenTimeStamp, sampleValType, vgpuInstanceSamplesCount,
                   utilizationSamples)
end

@checked function nvmlDeviceGetVgpuProcessUtilization(device, lastSeenTimeStamp,
                                                      vgpuProcessSamplesCount,
                                                      utilizationSamples)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetVgpuProcessUtilization, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Culonglong, Ptr{UInt32},
                    Ptr{nvmlVgpuProcessUtilizationSample_t}),
                   device, lastSeenTimeStamp, vgpuProcessSamplesCount, utilizationSamples)
end

@checked function nvmlVgpuInstanceGetAccountingMode(vgpuInstance, mode)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetAccountingMode, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Ptr{nvmlEnableState_t}),
                   vgpuInstance, mode)
end

@checked function nvmlVgpuInstanceGetAccountingPids(vgpuInstance, count, pids)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetAccountingPids, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, Ptr{UInt32}, Ptr{UInt32}),
                   vgpuInstance, count, pids)
end

@checked function nvmlVgpuInstanceGetAccountingStats(vgpuInstance, pid, stats)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceGetAccountingStats, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t, UInt32, Ptr{nvmlAccountingStats_t}),
                   vgpuInstance, pid, stats)
end

@checked function nvmlVgpuInstanceClearAccountingPids(vgpuInstance)
    initialize_api()
    @runtime_ccall((:nvmlVgpuInstanceClearAccountingPids, libnvml()), nvmlReturn_t,
                   (nvmlVgpuInstance_t,),
                   vgpuInstance)
end

@checked function nvmlGetBlacklistDeviceCount(deviceCount)
    initialize_api()
    @runtime_ccall((:nvmlGetBlacklistDeviceCount, libnvml()), nvmlReturn_t,
                   (Ptr{UInt32},),
                   deviceCount)
end

@checked function nvmlGetBlacklistDeviceInfoByIndex(index, info)
    initialize_api()
    @runtime_ccall((:nvmlGetBlacklistDeviceInfoByIndex, libnvml()), nvmlReturn_t,
                   (UInt32, Ptr{nvmlBlacklistDeviceInfo_t}),
                   index, info)
end

@checked function nvmlDeviceSetMigMode(device, mode, activationStatus)
    initialize_api()
    @runtime_ccall((:nvmlDeviceSetMigMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{nvmlReturn_t}),
                   device, mode, activationStatus)
end

@checked function nvmlDeviceGetMigMode(device, currentMode, pendingMode)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetMigMode, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}, Ptr{UInt32}),
                   device, currentMode, pendingMode)
end

@checked function nvmlDeviceGetGpuInstanceProfileInfo(device, profile, info)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetGpuInstanceProfileInfo, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{nvmlGpuInstanceProfileInfo_t}),
                   device, profile, info)
end

@checked function nvmlDeviceGetGpuInstancePossiblePlacements(device, profileId, placements,
                                                             count)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetGpuInstancePossiblePlacements, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{nvmlGpuInstancePlacement_t}, Ptr{UInt32}),
                   device, profileId, placements, count)
end

@checked function nvmlDeviceGetGpuInstanceRemainingCapacity(device, profileId, count)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetGpuInstanceRemainingCapacity, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{UInt32}),
                   device, profileId, count)
end

@checked function nvmlDeviceCreateGpuInstance(device, profileId, gpuInstance)
    initialize_api()
    @runtime_ccall((:nvmlDeviceCreateGpuInstance, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{nvmlGpuInstance_t}),
                   device, profileId, gpuInstance)
end

@checked function nvmlGpuInstanceDestroy(gpuInstance)
    initialize_api()
    @runtime_ccall((:nvmlGpuInstanceDestroy, libnvml()), nvmlReturn_t,
                   (nvmlGpuInstance_t,),
                   gpuInstance)
end

@checked function nvmlDeviceGetGpuInstances(device, profileId, gpuInstances, count)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetGpuInstances, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{nvmlGpuInstance_t}, Ptr{UInt32}),
                   device, profileId, gpuInstances, count)
end

@checked function nvmlDeviceGetGpuInstanceById(device, id, gpuInstance)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetGpuInstanceById, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{nvmlGpuInstance_t}),
                   device, id, gpuInstance)
end

@checked function nvmlGpuInstanceGetInfo(gpuInstance, info)
    initialize_api()
    @runtime_ccall((:nvmlGpuInstanceGetInfo, libnvml()), nvmlReturn_t,
                   (nvmlGpuInstance_t, Ptr{nvmlGpuInstanceInfo_t}),
                   gpuInstance, info)
end

@checked function nvmlGpuInstanceGetComputeInstanceProfileInfo(gpuInstance, profile,
                                                               engProfile, info)
    initialize_api()
    @runtime_ccall((:nvmlGpuInstanceGetComputeInstanceProfileInfo, libnvml()), nvmlReturn_t,
                   (nvmlGpuInstance_t, UInt32, UInt32,
                    Ptr{nvmlComputeInstanceProfileInfo_t}),
                   gpuInstance, profile, engProfile, info)
end

@checked function nvmlGpuInstanceGetComputeInstanceRemainingCapacity(gpuInstance,
                                                                     profileId, count)
    initialize_api()
    @runtime_ccall((:nvmlGpuInstanceGetComputeInstanceRemainingCapacity, libnvml()), nvmlReturn_t,
                   (nvmlGpuInstance_t, UInt32, Ptr{UInt32}),
                   gpuInstance, profileId, count)
end

@checked function nvmlGpuInstanceCreateComputeInstance(gpuInstance, profileId,
                                                       computeInstance)
    initialize_api()
    @runtime_ccall((:nvmlGpuInstanceCreateComputeInstance, libnvml()), nvmlReturn_t,
                   (nvmlGpuInstance_t, UInt32, Ptr{nvmlComputeInstance_t}),
                   gpuInstance, profileId, computeInstance)
end

@checked function nvmlComputeInstanceDestroy(computeInstance)
    initialize_api()
    @runtime_ccall((:nvmlComputeInstanceDestroy, libnvml()), nvmlReturn_t,
                   (nvmlComputeInstance_t,),
                   computeInstance)
end

@checked function nvmlGpuInstanceGetComputeInstances(gpuInstance, profileId,
                                                     computeInstances, count)
    initialize_api()
    @runtime_ccall((:nvmlGpuInstanceGetComputeInstances, libnvml()), nvmlReturn_t,
                   (nvmlGpuInstance_t, UInt32, Ptr{nvmlComputeInstance_t}, Ptr{UInt32}),
                   gpuInstance, profileId, computeInstances, count)
end

@checked function nvmlGpuInstanceGetComputeInstanceById(gpuInstance, id, computeInstance)
    initialize_api()
    @runtime_ccall((:nvmlGpuInstanceGetComputeInstanceById, libnvml()), nvmlReturn_t,
                   (nvmlGpuInstance_t, UInt32, Ptr{nvmlComputeInstance_t}),
                   gpuInstance, id, computeInstance)
end

@checked function nvmlComputeInstanceGetInfo(computeInstance, info)
    initialize_api()
    @runtime_ccall((:nvmlComputeInstanceGetInfo, libnvml()), nvmlReturn_t,
                   (nvmlComputeInstance_t, Ptr{nvmlComputeInstanceInfo_t}),
                   computeInstance, info)
end

@checked function nvmlDeviceIsMigDeviceHandle(device, isMigDevice)
    initialize_api()
    @runtime_ccall((:nvmlDeviceIsMigDeviceHandle, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, isMigDevice)
end

@checked function nvmlDeviceGetGpuInstanceId(device, id)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetGpuInstanceId, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, id)
end

@checked function nvmlDeviceGetComputeInstanceId(device, id)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetComputeInstanceId, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, id)
end

@checked function nvmlDeviceGetMaxMigDeviceCount(device, count)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetMaxMigDeviceCount, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{UInt32}),
                   device, count)
end

@checked function nvmlDeviceGetMigDeviceHandleByIndex(device, index, migDevice)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetMigDeviceHandleByIndex, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, UInt32, Ptr{nvmlDevice_t}),
                   device, index, migDevice)
end

@checked function nvmlDeviceGetDeviceHandleFromMigDeviceHandle(migDevice, device)
    initialize_api()
    @runtime_ccall((:nvmlDeviceGetDeviceHandleFromMigDeviceHandle, libnvml()), nvmlReturn_t,
                   (nvmlDevice_t, Ptr{nvmlDevice_t}),
                   migDevice, device)
end


text:
module MeshBridge

using Meshes: Meshes
using GeometryBasics: GeometryBasics

function Base.convert(::Type{Meshes.Mesh}, mesh::GeometryBasics.Mesh)
    vertexToIdx = Dict()
    for i in 1:length(mesh.position)
        vertex = mesh.position[i]
        if haskey(vertexToIdx, vertex)
            continue
        end
        vertexToIdx[vertex] = i
    end
    faces = []
    for triangle in mesh
        i1 = vertexToIdx[triangle[1]]
        i2 = vertexToIdx[triangle[2]]
        i3 = vertexToIdx[triangle[3]]
        push!(faces, (i1, i2, i3))
    end
    topology = Meshes.FullTopology(Meshes.connect.(faces))
    result = Meshes.SimpleMesh(
        [Meshes.Point([x[1], x[2], x[3]]) for x in mesh.position], topology
    )
    return result
end

function Base.convert(::Type{GeometryBasics.Mesh}, mesh::Meshes.Mesh)
    return GeometryBasics.Mesh(
        convert.(GeometryBasics.Point, mesh.points),
        [
            GeometryBasics.TriangleFace(x.indices) for
            x in (Meshes.collect(Meshes.elements(Meshes.topology(mesh))))
        ],
    )
end

function Base.convert(::Type{GeometryBasics.Triangle}, triangle::Meshes.Triangle)
    return GeometryBasics.Triangle(convert.(GeometryBasics.Point, triangle.vertices)...)
end

function Base.convert(::Type{Meshes.Triangle}, triangle::GeometryBasics.Triangle)
    return Meshes.Triangle(convert.(Meshes.Point, triangle.points))
end

function Base.convert(::Type{GeometryBasics.Point}, point::Meshes.Point)
    return GeometryBasics.Point(Meshes.coordinates(point))
end

function Base.convert(::Type{Meshes.Point}, point::GeometryBasics.Point)
    return Meshes.Point(point.data)
end

end

ext: jl


text:
using LinearAlgebraicRepresentation, ViewerGL, SparseArrays
Lar = LinearAlgebraicRepresentation; GL = ViewerGL

using Revise, OhMyREPL

wall = Lar.svg2lar("../../test/svg/assembly/wall.svg", flag=false)
openings = Lar.svg2lar("../../test/svg/assembly/openings.svg", flag=false)
rectangle = Lar.svg2lar("../../test/svg/assembly/rectangle.svg", flag=false)
box = Lar.svg2lar("../../test/svg/assembly/box.svg", flag=false)

assembly = Lar.Struct([wall , openings, rectangle, box])
V,EV = Lar.struct2lar(assembly)
GL.VIEW([ GL.GLFrame2, GL.GLGrid(V,EV, GL.COLORS[1],1) ]);
W, copEV, copFE, boolmatrix = Lar.bool2d(assembly)
@show Matrix(boolmatrix)

innerpoints = Lar.internalpoints2d(W,copEV,copFE[1:end,:])
points = convert(Array{Float64,2}, hcat(innerpoints...)')
GL.VIEW([ GL.GLFrame2, GL.GLGrid(V,EV, GL.COLORS[1],1), GL.GLPoints(points) ]);

A = boolmatrix[:,1]
B = boolmatrix[:,2]
C = boolmatrix[:,3]
D = boolmatrix[:,4]
expr = ( D .& .!(.&(A, .!B, .!C)) )# A - B - C
formula = Matrix(copFE)' * Int.(expr) # coord vector of Faces
V = convert(Lar.Points,W')
EV = Lar.cop2lar(copEV)
EVmin = [ev for (k,ev) in enumerate(EV) if abs(formula[k])==1 ]
V = Lar.normalize(V)
V = Lar.normalize(V)
GL.VIEW([ GL.GLFrame2, GL.GLGrid(V,EVmin, GL.COLORS[1],1) ]);

VV = [[k] for k in 1:size(V,2)];
model = (V,[VV, EV])
GL.VIEW( GL.numbering(.1)( model,GL.COLORS[1],0.1 ) );


text:
module TestBroadcast

include("preamble.jl")

f0 = WeightedAdd(1, 2)
f1 = WeightedAdd([1, 10], 2)

using Test
@test f0.(10, 100) == 210
@test f1.(10, 100) == [210, 300]
@test f0.([1, 10], 100) == [201, 210]
@test f1.([1, 10], 100) == [201, 300]

c0 = poly([1, 10], [2, 20])
c1 = AddCall(poly([1, 10], 0), poly(0, [2, 20]))
@test c0.(1) == c1.(1)
@test c0.([1, 2]) == c1.([1, 2])

end  # module


text:
@testset "pairs()" begin
    h = HashIndices{Int64}([3,6,9])
    p = pairs(h)
    @test p isa AbstractDictionary{Int64, Pair{Int64, Int64}}
    @test p[3] == (3 => 3)
    @test p[6] == (6 => 6)
    @test p[9] == (9 => 9)
    @test length(p) == 3
end


text:
# This file is a part of Julia. License is MIT: https://julialang.org/license

module Math

export sin, cos, sincos, tan, sinh, cosh, tanh, asin, acos, atan,
       asinh, acosh, atanh, sec, csc, cot, asec, acsc, acot,
       sech, csch, coth, asech, acsch, acoth,
       sinpi, cospi, sinc, cosc,
       cosd, cotd, cscd, secd, sind, tand, sincosd,
       acosd, acotd, acscd, asecd, asind, atand,
       rad2deg, deg2rad,
       log, log2, log10, log1p, exponent, exp, exp2, exp10, expm1,
       cbrt, sqrt, significand,
       hypot, max, min, minmax, ldexp, frexp,
       clamp, clamp!, modf, ^, mod2pi, rem2pi,
       @evalpoly, evalpoly

import .Base: log, exp, sin, cos, tan, sinh, cosh, tanh, asin,
             acos, atan, asinh, acosh, atanh, sqrt, log2, log10,
             max, min, minmax, ^, exp2, muladd, rem,
             exp10, expm1, log1p

using .Base: sign_mask, exponent_mask, exponent_one,
            exponent_half, uinttype, significand_mask,
            significand_bits, exponent_bits, exponent_bias,
            exponent_max, exponent_raw_max

using Core.Intrinsics: sqrt_llvm

using .Base: IEEEFloat

@noinline function throw_complex_domainerror(f::Symbol, x)
    throw(DomainError(x, string("$f will only return a complex result if called with a ",
                                "complex argument. Try $f(Complex(x)).")))
end
@noinline function throw_exp_domainerror(x)
    throw(DomainError(x, string("Exponentiation yielding a complex result requires a ",
                                "complex argument.\nReplace x^y with (x+0im)^y, ",
                                "Complex(x)^y, or similar.")))
end

# non-type specific math functions

"""
    clamp(x, lo, hi)

Return `x` if `lo <= x <= hi`. If `x > hi`, return `hi`. If `x < lo`, return `lo`. Arguments
are promoted to a common type.

# Examples
```jldoctest
julia> clamp.([pi, 1.0, big(10.)], 2., 9.)
3-element Array{BigFloat,1}:
 3.141592653589793238462643383279502884197169399375105820974944592307816406286198
 2.0
 9.0

julia> clamp.([11,8,5],10,6) # an example where lo > hi
3-element Array{Int64,1}:
  6
  6
 10
```
"""
clamp(x::X, lo::L, hi::H) where {X,L,H} =
    ifelse(x > hi, convert(promote_type(X,L,H), hi),
           ifelse(x < lo,
                  convert(promote_type(X,L,H), lo),
                  convert(promote_type(X,L,H), x)))

"""
    clamp(x, T)::T

Clamp `x` between `typemin(T)` and `typemax(T)` and convert the result to type `T`.

# Examples
```jldoctest
julia> clamp(200, Int8)
127
julia> clamp(-200, Int8)
-128
```
"""
clamp(x, ::Type{T}) where {T<:Integer} = clamp(x, typemin(T), typemax(T)) % T

"""
    clamp!(array::AbstractArray, lo, hi)

Restrict values in `array` to the specified range, in-place.
See also [`clamp`](@ref).
"""
function clamp!(x::AbstractArray, lo, hi)
    @inbounds for i in eachindex(x)
        x[i] = clamp(x[i], lo, hi)
    end
    x
end

"""
    evalpoly(x, p)

Evaluate the polynomial ``\\sum_k x^{k-1} p[k]`` for the coefficients `p[1]`, `p[2]`, ...;
that is, the coefficients are given in ascending order by power of `x`.
Loops are unrolled at compile time if the number of coefficients is statically known, i.e.
when `p` is a `Tuple`.
This function generates efficient code using Horner's method if `x` is real, or using
a Goertzel-like [^DK62] algorithm if `x` is complex.

[^DK62]: Donald Knuth, Art of Computer Programming, Volume 2: Seminumerical Algorithms, Sec. 4.6.4.

!!! compat "Julia 1.4"
    This function requires Julia 1.4 or later.

# Example
```jldoctest
julia> evalpoly(2, (1, 2, 3))
17
```
"""
function evalpoly(x, p::Tuple)
    if @generated
        N = length(p.parameters)
        ex = :(p[end])
        for i in N-1:-1:1
            ex = :(muladd(x, $ex, p[$i]))
        end
        ex
    else
        _evalpoly(x, p)
    end
end

evalpoly(x, p::AbstractVector) = _evalpoly(x, p)

function _evalpoly(x, p)
    N = length(p)
    ex = p[end]
    for i in N-1:-1:1
        ex = muladd(x, ex, p[i])
    end
    ex
end

function evalpoly(z::Complex, p::Tuple)
    if @generated
        N = length(p.parameters)
        a = :(p[end])
        b = :(p[end-1])
        as = []
        for i in N-2:-1:1
            ai = Symbol("a", i)
            push!(as, :($ai = $a))
            a = :(muladd(r, $ai, $b))
            b = :(muladd(-s, $ai, p[$i]))
        end
        ai = :a0
        push!(as, :($ai = $a))
        C = Expr(:block,
                 :(x = real(z)),
                 :(y = imag(z)),
                 :(r = x + x),
                 :(s = muladd(x, x, y*y)),
                 as...,
                 :(muladd($ai, z, $b)))
    else
        _evalpoly(z, p)
    end
end
evalpoly(z::Complex, p::Tuple{<:Any}) = p[1]

evalpoly(z::Complex, p::AbstractVector) = _evalpoly(z, p)

function _evalpoly(z::Complex, p)
    length(p) == 1 && return p[1]
    N = length(p)
    a = p[end]
    b = p[end-1]

    x = real(z)
    y = imag(z)
    r = 2x
    s = muladd(x, x, y*y)
    for i in N-2:-1:1
        ai = a
        a = muladd(r, ai, b)
        b = muladd(-s, ai, p[i])
    end
    ai = a
    muladd(ai, z, b)
end

"""
    @horner(x, p...)

Evaluate `p[1] + x * (p[2] + x * (....))`, i.e. a polynomial via Horner's rule.
"""
macro horner(x, p...)
     xesc, pesc = esc(x), esc.(p)
    :(invoke(evalpoly, Tuple{Any, Tuple}, $xesc, ($(pesc...),)))
end

# Evaluate p[1] + z*p[2] + z^2*p[3] + ... + z^(n-1)*p[n].  This uses
# Horner's method if z is real, but for complex z it uses a more
# efficient algorithm described in Knuth, TAOCP vol. 2, section 4.6.4,
# equation (3).

"""
    @evalpoly(z, c...)

Evaluate the polynomial ``\\sum_k z^{k-1} c[k]`` for the coefficients `c[1]`, `c[2]`, ...;
that is, the coefficients are given in ascending order by power of `z`.  This macro expands
to efficient inline code that uses either Horner's method or, for complex `z`, a more
efficient Goertzel-like algorithm.

# Examples
```jldoctest
julia> @evalpoly(3, 1, 0, 1)
10

julia> @evalpoly(2, 1, 0, 1)
5

julia> @evalpoly(2, 1, 1, 1)
7
```
"""
macro evalpoly(z, p...)
    zesc, pesc = esc(z), esc.(p)
    :(evalpoly($zesc, ($(pesc...),)))
end

"""
    rad2deg(x)

Convert `x` from radians to degrees.

# Examples
```jldoctest
julia> rad2deg(pi)
180.0
```
"""
rad2deg(z::AbstractFloat) = z * (180 / oftype(z, pi))

"""
    deg2rad(x)

Convert `x` from degrees to radians.

# Examples
```jldoctest
julia> deg2rad(90)
1.5707963267948966
```
"""
deg2rad(z::AbstractFloat) = z * (oftype(z, pi) / 180)
rad2deg(z::Real) = rad2deg(float(z))
deg2rad(z::Real) = deg2rad(float(z))
rad2deg(z::Number) = (z/pi)*180
deg2rad(z::Number) = (z*pi)/180

log(b::T, x::T) where {T<:Number} = log(x)/log(b)

"""
    log(b,x)

Compute the base `b` logarithm of `x`. Throws [`DomainError`](@ref) for negative
[`Real`](@ref) arguments.

# Examples
```jldoctest; filter = r"Stacktrace:(\\n \\[[0-9]+\\].*)*"
julia> log(4,8)
1.5

julia> log(4,2)
0.5

julia> log(-2, 3)
ERROR: DomainError with -2.0:
log will only return a complex result if called with a complex argument. Try log(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:31
[...]

julia> log(2, -3)
ERROR: DomainError with -3.0:
log will only return a complex result if called with a complex argument. Try log(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:31
[...]
```

!!! note
    If `b` is a power of 2 or 10, [`log2`](@ref) or [`log10`](@ref) should be used, as these will
    typically be faster and more accurate. For example,

    ```jldoctest
    julia> log(100,1000000)
    2.9999999999999996

    julia> log10(1000000)/2
    3.0
    ```
"""
log(b::Number, x::Number) = log(promote(b,x)...)

# type specific math functions

const libm = Base.libm_name

# functions with no domain error
"""
    sinh(x)

Compute hyperbolic sine of `x`.
"""
sinh(x::Number)

"""
    cosh(x)

Compute hyperbolic cosine of `x`.
"""
cosh(x::Number)

"""
    tanh(x)

Compute hyperbolic tangent of `x`.
"""
tanh(x::Number)

"""
    atan(y)
    atan(y, x)

Compute the inverse tangent of `y` or `y/x`, respectively.

For one argument, this is the angle in radians between the positive *x*-axis and the point
(1, *y*), returning a value in the interval ``[-\\pi/2, \\pi/2]``.

For two arguments, this is the angle in radians between the positive *x*-axis and the
point (*x*, *y*), returning a value in the interval ``[-\\pi, \\pi]``. This corresponds to a
standard [`atan2`](https://en.wikipedia.org/wiki/Atan2) function.
"""
atan(x::Number)

"""
    asinh(x)

Compute the inverse hyperbolic sine of `x`.
"""
asinh(x::Number)

"""
    expm1(x)

Accurately compute ``e^x-1``.
"""
expm1(x)
for f in (:exp2, :expm1)
    @eval begin
        ($f)(x::Float64) = ccall(($(string(f)),libm), Float64, (Float64,), x)
        ($f)(x::Float32) = ccall(($(string(f,"f")),libm), Float32, (Float32,), x)
        ($f)(x::Real) = ($f)(float(x))
    end
end

"""
    exp2(x)

Compute the base 2 exponential of `x`, in other words ``2^x``.

# Examples
```jldoctest
julia> exp2(5)
32.0
```
"""
exp2(x::AbstractFloat) = 2^x

"""
    exp10(x)

Compute the base 10 exponential of `x`, in other words ``10^x``.

# Examples
```jldoctest
julia> exp10(2)
100.0
```
"""
exp10(x::AbstractFloat) = 10^x

for f in (:sinh, :cosh, :tanh, :atan, :asinh, :exp, :expm1)
    @eval ($f)(x::AbstractFloat) = error("not implemented for ", typeof(x))
end

# functions with special cases for integer arguments
@inline function exp2(x::Base.BitInteger)
    if x > 1023
        Inf64
    elseif x <= -1023
        # if -1073 < x <= -1023 then Result will be a subnormal number
        # Hex literal with padding must be used to work on 32bit machine
        reinterpret(Float64, 0x0000_0000_0000_0001 << ((x + 1074) % UInt))
    else
        # We will cast everything to Int64 to avoid errors in case of Int128
        # If x is a Int128, and is outside the range of Int64, then it is not -1023<x<=1023
        reinterpret(Float64, (exponent_bias(Float64) + (x % Int64)) << (significand_bits(Float64) % UInt))
    end
end

# utility for converting NaN return to DomainError
# the branch in nan_dom_err prevents its callers from inlining, so be sure to force it
# until the heuristics can be improved
@inline nan_dom_err(out, x) = isnan(out) & !isnan(x) ? throw(DomainError(x, "NaN result for non-NaN input.")) : out

# functions that return NaN on non-NaN argument for domain error
"""
    sin(x)

Compute sine of `x`, where `x` is in radians.
"""
sin(x::Number)

"""
    cos(x)

Compute cosine of `x`, where `x` is in radians.
"""
cos(x::Number)

"""
    tan(x)

Compute tangent of `x`, where `x` is in radians.
"""
tan(x::Number)

"""
    asin(x)

Compute the inverse sine of `x`, where the output is in radians.
"""
asin(x::Number)

"""
    acos(x)

Compute the inverse cosine of `x`, where the output is in radians
"""
acos(x::Number)

"""
    acosh(x)

Compute the inverse hyperbolic cosine of `x`.
"""
acosh(x::Number)

"""
    atanh(x)

Compute the inverse hyperbolic tangent of `x`.
"""
atanh(x::Number)

"""
    log(x)

Compute the natural logarithm of `x`. Throws [`DomainError`](@ref) for negative
[`Real`](@ref) arguments. Use complex negative arguments to obtain complex results.

# Examples
```jldoctest; filter = r"Stacktrace:(\\n \\[[0-9]+\\].*)*"
julia> log(2)
0.6931471805599453

julia> log(-3)
ERROR: DomainError with -3.0:
log will only return a complex result if called with a complex argument. Try log(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:31
[...]
```
"""
log(x::Number)

"""
    log2(x)

Compute the logarithm of `x` to base 2. Throws [`DomainError`](@ref) for negative
[`Real`](@ref) arguments.

# Examples
```jldoctest; filter = r"Stacktrace:(\\n \\[[0-9]+\\].*)*"
julia> log2(4)
2.0

julia> log2(10)
3.321928094887362

julia> log2(-2)
ERROR: DomainError with -2.0:
NaN result for non-NaN input.
Stacktrace:
 [1] nan_dom_err at ./math.jl:325 [inlined]
[...]
```
"""
log2(x)

"""
    log10(x)

Compute the logarithm of `x` to base 10.
Throws [`DomainError`](@ref) for negative [`Real`](@ref) arguments.

# Examples
```jldoctest; filter = r"Stacktrace:(\\n \\[[0-9]+\\].*)*"
julia> log10(100)
2.0

julia> log10(2)
0.3010299956639812

julia> log10(-2)
ERROR: DomainError with -2.0:
NaN result for non-NaN input.
Stacktrace:
 [1] nan_dom_err at ./math.jl:325 [inlined]
[...]
```
"""
log10(x)

"""
    log1p(x)

Accurate natural logarithm of `1+x`. Throws [`DomainError`](@ref) for [`Real`](@ref)
arguments less than -1.

# Examples
```jldoctest; filter = r"Stacktrace:(\\n \\[[0-9]+\\].*)*"
julia> log1p(-0.5)
-0.6931471805599453

julia> log1p(0)
0.0

julia> log1p(-2)
ERROR: DomainError with -2.0:
log1p will only return a complex result if called with a complex argument. Try log1p(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:31
[...]
```
"""
log1p(x)
for f in (:log2, :log10)
    @eval begin
        @inline ($f)(x::Float64) = nan_dom_err(ccall(($(string(f)), libm), Float64, (Float64,), x), x)
        @inline ($f)(x::Float32) = nan_dom_err(ccall(($(string(f, "f")), libm), Float32, (Float32,), x), x)
        @inline ($f)(x::Real) = ($f)(float(x))
    end
end

@inline function sqrt(x::Union{Float32,Float64})
    x < zero(x) && throw_complex_domainerror(:sqrt, x)
    sqrt_llvm(x)
end

"""
    sqrt(x)

Return ``\\sqrt{x}``. Throws [`DomainError`](@ref) for negative [`Real`](@ref) arguments.
Use complex negative arguments instead. The prefix operator `√` is equivalent to `sqrt`.

# Examples
```jldoctest; filter = r"Stacktrace:(\\n \\[[0-9]+\\].*)*"
julia> sqrt(big(81))
9.0

julia> sqrt(big(-81))
ERROR: DomainError with -81.0:
NaN result for non-NaN input.
Stacktrace:
 [1] sqrt(::BigFloat) at ./mpfr.jl:501
[...]

julia> sqrt(big(complex(-81)))
0.0 + 9.0im
```
"""
sqrt(x::Real) = sqrt(float(x))

"""
    hypot(x, y)

Compute the hypotenuse ``\\sqrt{|x|^2+|y|^2}`` avoiding overflow and underflow.

This code is an implementation of the algorithm described in:
An Improved Algorithm for `hypot(a,b)`
by Carlos F. Borges
The article is available online at ArXiv at the link
  https://arxiv.org/abs/1904.09481

# Examples
```jldoctest; filter = r"Stacktrace:(\\n \\[[0-9]+\\].*)*"
julia> a = Int64(10)^10;

julia> hypot(a, a)
1.4142135623730951e10

julia> √(a^2 + a^2) # a^2 overflows
ERROR: DomainError with -2.914184810805068e18:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
[...]

julia> hypot(3, 4im)
5.0
```
"""
hypot(x::Number, y::Number) = hypot(promote(x, y)...)
hypot(x::Complex, y::Complex) = hypot(abs(x), abs(y))
hypot(x::T, y::T) where {T<:Real} = hypot(float(x), float(y))
function hypot(x::T, y::T) where {T<:Number}
    if !iszero(x)
        z = y/x
        z2 = z*z

        abs(x) * sqrt(oneunit(z2) + z2)
    else
        abs(y)
    end
end

function hypot(x::T, y::T) where T<:AbstractFloat
    # Return Inf if either or both inputs is Inf (Compliance with IEEE754)
    if isinf(x) || isinf(y)
        return T(Inf)
    end

    # Order the operands
    ax,ay = abs(x), abs(y)
    if ay > ax
        ax,ay = ay,ax
    end

    # Widely varying operands
    if ay <= ax*sqrt(eps(T)/2)  #Note: This also gets ay == 0
        return ax
    end

    # Operands do not vary widely
    scale = eps(sqrt(floatmin(T)))  #Rescaling constant
    if ax > sqrt(floatmax(T)/2)
        ax = ax*scale
        ay = ay*scale
        scale = inv(scale)
    elseif ay < sqrt(floatmin(T))
        ax = ax/scale
        ay = ay/scale
    else
        scale = one(scale)
    end
    h = sqrt(muladd(ax,ax,ay*ay))
    # This branch is correctly rounded but requires a native hardware fma.
    if Base.Math.FMA_NATIVE
        hsquared = h*h
        axsquared = ax*ax
        h -= (fma(-ay,ay,hsquared-axsquared) + fma(h,h,-hsquared) - fma(ax,ax,-axsquared))/(2*h)
    # This branch is within one ulp of correctly rounded.
    else
        if h <= 2*ay
            delta = h-ay
            h -= muladd(delta,delta-2*(ax-ay),ax*(2*delta - ax))/(2*h)
        else
            delta = h-ax
            h -= muladd(delta,delta,muladd(ay,(4*delta-ay),2*delta*(ax-2*ay)))/(2*h)
        end
    end
    return h*scale
end

"""
    hypot(x...)

Compute the hypotenuse ``\\sqrt{\\sum |x_i|^2}`` avoiding overflow and underflow.

# Examples
```jldoctest
julia> hypot(-5.7)
5.7

julia> hypot(3, 4im, 12.0)
13.0
```
"""
hypot(x::Number...) = sqrt(sum(abs2(y) for y in x))

atan(y::Real, x::Real) = atan(promote(float(y),float(x))...)
atan(y::T, x::T) where {T<:AbstractFloat} = Base.no_op_err("atan", T)

max(x::T, y::T) where {T<:AbstractFloat} = ifelse((y > x) | (signbit(y) < signbit(x)),
                                    ifelse(isnan(x), x, y), ifelse(isnan(y), y, x))

min(x::T, y::T) where {T<:AbstractFloat} = ifelse((y < x) | (signbit(y) > signbit(x)),
                                    ifelse(isnan(x), x, y), ifelse(isnan(y), y, x))

minmax(x::T, y::T) where {T<:AbstractFloat} =
    ifelse(isnan(x) | isnan(y), ifelse(isnan(x), (x,x), (y,y)),
           ifelse((y > x) | (signbit(x) > signbit(y)), (x,y), (y,x)))

"""
    ldexp(x, n)

Compute ``x \\times 2^n``.

# Examples
```jldoctest
julia> ldexp(5., 2)
20.0
```
"""
function ldexp(x::T, e::Integer) where T<:IEEEFloat
    xu = reinterpret(Unsigned, x)
    xs = xu & ~sign_mask(T)
    xs >= exponent_mask(T) && return x # NaN or Inf
    k = Int(xs >> significand_bits(T))
    if k == 0 # x is subnormal
        xs == 0 && return x # +-0
        m = leading_zeros(xs) - exponent_bits(T)
        ys = xs << unsigned(m)
        xu = ys | (xu & sign_mask(T))
        k = 1 - m
        # underflow, otherwise may have integer underflow in the following n + k
        e < -50000 && return flipsign(T(0.0), x)
    end
    # For cases where e of an Integer larger than Int make sure we properly
    # overflow/underflow; this is optimized away otherwise.
    if e > typemax(Int)
        return flipsign(T(Inf), x)
    elseif e < typemin(Int)
        return flipsign(T(0.0), x)
    end
    n = e % Int
    k += n
    # overflow, if k is larger than maximum possible exponent
    if k >= exponent_raw_max(T)
        return flipsign(T(Inf), x)
    end
    if k > 0 # normal case
        xu = (xu & ~exponent_mask(T)) | (rem(k, uinttype(T)) << significand_bits(T))
        return reinterpret(T, xu)
    else # subnormal case
        if k <= -significand_bits(T) # underflow
            # overflow, for the case of integer overflow in n + k
            e > 50000 && return flipsign(T(Inf), x)
            return flipsign(T(0.0), x)
        end
        k += significand_bits(T)
        z = T(2.0)^-significand_bits(T)
        xu = (xu & ~exponent_mask(T)) | (rem(k, uinttype(T)) << significand_bits(T))
        return z*reinterpret(T, xu)
    end
end
ldexp(x::Float16, q::Integer) = Float16(ldexp(Float32(x), q))

"""
    exponent(x) -> Int

Get the exponent of a normalized floating-point number.
"""
function exponent(x::T) where T<:IEEEFloat
    @noinline throw1(x) = throw(DomainError(x, "Cannot be NaN or Inf."))
    @noinline throw2(x) = throw(DomainError(x, "Cannot be subnormal converted to 0."))
    xs = reinterpret(Unsigned, x) & ~sign_mask(T)
    xs >= exponent_mask(T) && throw1(x)
    k = Int(xs >> significand_bits(T))
    if k == 0 # x is subnormal
        xs == 0 && throw2(x)
        m = leading_zeros(xs) - exponent_bits(T)
        k = 1 - m
    end
    return k - exponent_bias(T)
end

"""
    significand(x)

Extract the `significand(s)` (a.k.a. mantissa), in binary representation, of a
floating-point number. If `x` is a non-zero finite number, then the result will be
a number of the same type on the interval ``[1,2)``. Otherwise `x` is returned.

# Examples
```jldoctest
julia> significand(15.2)/15.2
0.125

julia> significand(15.2)*8
15.2
```
"""
function significand(x::T) where T<:IEEEFloat
    xu = reinterpret(Unsigned, x)
    xs = xu & ~sign_mask(T)
    xs >= exponent_mask(T) && return x # NaN or Inf
    if xs <= (~exponent_mask(T) & ~sign_mask(T)) # x is subnormal
        xs == 0 && return x # +-0
        m = unsigned(leading_zeros(xs) - exponent_bits(T))
        xs <<= m
        xu = xs | (xu & sign_mask(T))
    end
    xu = (xu & ~exponent_mask(T)) | exponent_one(T)
    return reinterpret(T, xu)
end

"""
    frexp(val)

Return `(x,exp)` such that `x` has a magnitude in the interval ``[1/2, 1)`` or 0,
and `val` is equal to ``x \\times 2^{exp}``.
"""
function frexp(x::T) where T<:IEEEFloat
    xu = reinterpret(Unsigned, x)
    xs = xu & ~sign_mask(T)
    xs >= exponent_mask(T) && return x, 0 # NaN or Inf
    k = Int(xs >> significand_bits(T))
    if k == 0 # x is subnormal
        xs == 0 && return x, 0 # +-0
        m = leading_zeros(xs) - exponent_bits(T)
        xs <<= unsigned(m)
        xu = xs | (xu & sign_mask(T))
        k = 1 - m
    end
    k -= (exponent_bias(T) - 1)
    xu = (xu & ~exponent_mask(T)) | exponent_half(T)
    return reinterpret(T, xu), k
end

rem(x::Float64, y::Float64, ::RoundingMode{:Nearest}) =
    ccall((:remainder, libm),Float64,(Float64,Float64),x,y)
rem(x::Float32, y::Float32, ::RoundingMode{:Nearest}) =
    ccall((:remainderf, libm),Float32,(Float32,Float32),x,y)
rem(x::Float16, y::Float16, r::RoundingMode{:Nearest}) = Float16(rem(Float32(x), Float32(y), r))

"""
    modf(x)

Return a tuple `(fpart, ipart)` of the fractional and integral parts of a number. Both parts
have the same sign as the argument.

# Examples
```jldoctest
julia> modf(3.5)
(0.5, 3.0)

julia> modf(-3.5)
(-0.5, -3.0)
```
"""
modf(x) = isinf(x) ? (flipsign(zero(x), x), x) : (rem(x, one(x)), trunc(x))

function modf(x::Float32)
    temp = Ref{Float32}()
    f = ccall((:modff, libm), Float32, (Float32, Ptr{Float32}), x, temp)
    f, temp[]
end

function modf(x::Float64)
    temp = Ref{Float64}()
    f = ccall((:modf, libm), Float64, (Float64, Ptr{Float64}), x, temp)
    f, temp[]
end

@inline function ^(x::Float64, y::Float64)
    z = ccall("llvm.pow.f64", llvmcall, Float64, (Float64, Float64), x, y)
    if isnan(z) & !isnan(x+y)
        throw_exp_domainerror(x)
    end
    z
end
@inline function ^(x::Float32, y::Float32)
    z = ccall("llvm.pow.f32", llvmcall, Float32, (Float32, Float32), x, y)
    if isnan(z) & !isnan(x+y)
        throw_exp_domainerror(x)
    end
    z
end
@inline function ^(x::Float64, y::Integer)
    y == -1 && return inv(x)
    y == 0 && return one(x)
    y == 1 && return x
    y == 2 && return x*x
    y == 3 && return x*x*x
    ccall("llvm.pow.f64", llvmcall, Float64, (Float64, Float64), x, Float64(y))
end
@inline function ^(x::Float32, y::Integer)
    y == -1 && return inv(x)
    y == 0 && return one(x)
    y == 1 && return x
    y == 2 && return x*x
    y == 3 && return x*x*x
    ccall("llvm.pow.f32", llvmcall, Float32, (Float32, Float32), x, Float32(y))
end
@inline ^(x::Float16, y::Integer) = Float16(Float32(x) ^ y)
@inline literal_pow(::typeof(^), x::Float16, ::Val{p}) where {p} = Float16(literal_pow(^,Float32(x),Val(p)))

## rem2pi-related calculations ##

function add22condh(xh::Float64, xl::Float64, yh::Float64, yl::Float64)
    # This algorithm, due to Dekker, computes the sum of two
    # double-double numbers and returns the high double. References:
    # [1] http://www.digizeitschriften.de/en/dms/img/?PID=GDZPPN001170007
    # [2] https://doi.org/10.1007/BF01397083
    r = xh+yh
    s = (abs(xh) > abs(yh)) ? (xh-r+yh+yl+xl) : (yh-r+xh+xl+yl)
    zh = r+s
    return zh
end

# multiples of pi/2, as double-double (ie with "tail")
const pi1o2_h  = 1.5707963267948966     # convert(Float64, pi * BigFloat(1/2))
const pi1o2_l  = 6.123233995736766e-17  # convert(Float64, pi * BigFloat(1/2) - pi1o2_h)

const pi2o2_h  = 3.141592653589793      # convert(Float64, pi * BigFloat(1))
const pi2o2_l  = 1.2246467991473532e-16 # convert(Float64, pi * BigFloat(1) - pi2o2_h)

const pi3o2_h  = 4.71238898038469       # convert(Float64, pi * BigFloat(3/2))
const pi3o2_l  = 1.8369701987210297e-16 # convert(Float64, pi * BigFloat(3/2) - pi3o2_h)

const pi4o2_h  = 6.283185307179586      # convert(Float64, pi * BigFloat(2))
const pi4o2_l  = 2.4492935982947064e-16 # convert(Float64, pi * BigFloat(2) - pi4o2_h)

"""
    rem2pi(x, r::RoundingMode)

Compute the remainder of `x` after integer division by `2π`, with the quotient rounded
according to the rounding mode `r`. In other words, the quantity

    x - 2π*round(x/(2π),r)

without any intermediate rounding. This internally uses a high precision approximation of
2π, and so will give a more accurate result than `rem(x,2π,r)`

- if `r == RoundNearest`, then the result is in the interval ``[-π, π]``. This will generally
  be the most accurate result. See also [`RoundNearest`](@ref).

- if `r == RoundToZero`, then the result is in the interval ``[0, 2π]`` if `x` is positive,.
  or ``[-2π, 0]`` otherwise. See also [`RoundToZero`](@ref).

- if `r == RoundDown`, then the result is in the interval ``[0, 2π]``.
  See also [`RoundDown`](@ref).
- if `r == RoundUp`, then the result is in the interval ``[-2π, 0]``.
  See also [`RoundUp`](@ref).

# Examples
```jldoctest
julia> rem2pi(7pi/4, RoundNearest)
-0.7853981633974485

julia> rem2pi(7pi/4, RoundDown)
5.497787143782138
```
"""
function rem2pi end
function rem2pi(x::Float64, ::RoundingMode{:Nearest})
    abs(x) < pi && return x

    n,y = rem_pio2_kernel(x)

    if iseven(n)
        if n & 2 == 2 # n % 4 == 2: add/subtract pi
            if y.hi <= 0
                return add22condh(y.hi,y.lo,pi2o2_h,pi2o2_l)
            else
                return add22condh(y.hi,y.lo,-pi2o2_h,-pi2o2_l)
            end
        else          # n % 4 == 0: add 0
            return y.hi+y.lo
        end
    else
        if n & 2 == 2 # n % 4 == 3: subtract pi/2
            return add22condh(y.hi,y.lo,-pi1o2_h,-pi1o2_l)
        else          # n % 4 == 1: add pi/2
            return add22condh(y.hi,y.lo,pi1o2_h,pi1o2_l)
        end
    end
end
function rem2pi(x::Float64, ::RoundingMode{:ToZero})
    ax = abs(x)
    ax <= 2*Float64(pi,RoundDown) && return x

    n,y = rem_pio2_kernel(x)

    if iseven(n)
        if n & 2 == 2 # n % 4 == 2: add pi
            z = add22condh(y.hi,y.lo,pi2o2_h,pi2o2_l)
        else          # n % 4 == 0: add 0 or 2pi
            if y.hi > 0
                z = y.hi+y.lo
            else      # negative: add 2pi
                z = add22condh(y.hi,y.lo,pi4o2_h,pi4o2_l)
            end
        end
    else
        if n & 2 == 2 # n % 4 == 3: add 3pi/2
            z = add22condh(y.hi,y.lo,pi3o2_h,pi3o2_l)
        else          # n % 4 == 1: add pi/2
            z = add22condh(y.hi,y.lo,pi1o2_h,pi1o2_l)
        end
    end
    copysign(z,x)
end
function rem2pi(x::Float64, ::RoundingMode{:Down})
    if x < pi4o2_h
        if x >= 0
            return x
        elseif x > -pi4o2_h
            return add22condh(x,0.0,pi4o2_h,pi4o2_l)
        end
    end

    n,y = rem_pio2_kernel(x)

    if iseven(n)
        if n & 2 == 2 # n % 4 == 2: add pi
            return add22condh(y.hi,y.lo,pi2o2_h,pi2o2_l)
        else          # n % 4 == 0: add 0 or 2pi
            if y.hi > 0
                return y.hi+y.lo
            else      # negative: add 2pi
                return add22condh(y.hi,y.lo,pi4o2_h,pi4o2_l)
            end
        end
    else
        if n & 2 == 2 # n % 4 == 3: add 3pi/2
            return add22condh(y.hi,y.lo,pi3o2_h,pi3o2_l)
        else          # n % 4 == 1: add pi/2
            return add22condh(y.hi,y.lo,pi1o2_h,pi1o2_l)
        end
    end
end
function rem2pi(x::Float64, ::RoundingMode{:Up})
    if x > -pi4o2_h
        if x <= 0
            return x
        elseif x < pi4o2_h
            return add22condh(x,0.0,-pi4o2_h,-pi4o2_l)
        end
    end

    n,y = rem_pio2_kernel(x)

    if iseven(n)
        if n & 2 == 2 # n % 4 == 2: sub pi
            return add22condh(y.hi,y.lo,-pi2o2_h,-pi2o2_l)
        else          # n % 4 == 0: sub 0 or 2pi
            if y.hi < 0
                return y.hi+y.lo
            else      # positive: sub 2pi
                return add22condh(y.hi,y.lo,-pi4o2_h,-pi4o2_l)
            end
        end
    else
        if n & 2 == 2 # n % 4 == 3: sub pi/2
            return add22condh(y.hi,y.lo,-pi1o2_h,-pi1o2_l)
        else          # n % 4 == 1: sub 3pi/2
            return add22condh(y.hi,y.lo,-pi3o2_h,-pi3o2_l)
        end
    end
end

rem2pi(x::Float32, r::RoundingMode) = Float32(rem2pi(Float64(x), r))
rem2pi(x::Float16, r::RoundingMode) = Float16(rem2pi(Float64(x), r))
rem2pi(x::Int32, r::RoundingMode) = rem2pi(Float64(x), r)
function rem2pi(x::Int64, r::RoundingMode)
    fx = Float64(x)
    fx == x || throw(ArgumentError("Int64 argument to rem2pi is too large: $x"))
    rem2pi(fx, r)
end

"""
    mod2pi(x)

Modulus after division by `2π`, returning in the range ``[0,2π)``.

This function computes a floating point representation of the modulus after division by
numerically exact `2π`, and is therefore not exactly the same as `mod(x,2π)`, which would
compute the modulus of `x` relative to division by the floating-point number `2π`.

!!! note
    Depending on the format of the input value, the closest representable value to 2π may
    be less than 2π. For example, the expression `mod2pi(2π)` will not return `0`, because
    the intermediate value of `2*π` is a `Float64` and `2*Float64(π) < 2*big(π)`. See
    [`rem2pi`](@ref) for more refined control of this behavior.

# Examples
```jldoctest
julia> mod2pi(9*pi/4)
0.7853981633974481
```
"""
mod2pi(x) = rem2pi(x,RoundDown)

# generic fallback; for number types, promotion.jl does promotion

"""
    muladd(x, y, z)

Combined multiply-add: computes `x*y+z`, but allowing the add and multiply to be merged
with each other or with surrounding operations for performance.
For example, this may be implemented as an [`fma`](@ref) if the hardware supports it
efficiently.
The result can be different on different machines and can also be different on the same machine
due to constant propagation or other optimizations.
See [`fma`](@ref).

# Examples
```jldoctest
julia> muladd(3, 2, 1)
7

julia> 3 * 2 + 1
7
```
"""
muladd(x,y,z) = x*y+z

# Float16 definitions

for func in (:sin,:cos,:tan,:asin,:acos,:atan,:sinh,:cosh,:tanh,:asinh,:acosh,
             :atanh,:exp,:exp2,:exp10,:log,:log2,:log10,:sqrt,:lgamma,:log1p)
    @eval begin
        $func(a::Float16) = Float16($func(Float32(a)))
        $func(a::ComplexF16) = ComplexF16($func(ComplexF32(a)))
    end
end

for func in (:atan,:hypot)
    @eval begin
        $func(a::Float16,b::Float16) = Float16($func(Float32(a),Float32(b)))
    end
end

cbrt(a::Float16) = Float16(cbrt(Float32(a)))
sincos(a::Float16) = Float16.(sincos(Float32(a)))

# helper functions for Libm functionality

"""
    highword(x)

Return the high word of `x` as a `UInt32`.
"""
@inline highword(x::Float64) = highword(reinterpret(UInt64, x))
@inline highword(x::UInt64)  = (x >>> 32) % UInt32
@inline highword(x::Float32) = reinterpret(UInt32, x)

@inline fromhighword(::Type{Float64}, u::UInt32) = reinterpret(Float64, UInt64(u) << 32)
@inline fromhighword(::Type{Float32}, u::UInt32) = reinterpret(Float32, u)

"""
    poshighword(x)

Return positive part of the high word of `x` as a `UInt32`.
"""
@inline poshighword(x::Float64) = poshighword(reinterpret(UInt64, x))
@inline poshighword(x::UInt64)  = highword(x) & 0x7fffffff
@inline poshighword(x::Float32) = highword(x) & 0x7fffffff

# More special functions
include("special/cbrt.jl")
include("special/exp.jl")
include("special/exp10.jl")
include("special/ldexp_exp.jl")
include("special/hyperbolic.jl")
include("special/trig.jl")
include("special/rem_pio2.jl")
include("special/log.jl")

# `missing` definitions for functions in this module
for f in (:(acos), :(acosh), :(asin), :(asinh), :(atan), :(atanh),
          :(sin), :(sinh), :(cos), :(cosh), :(tan), :(tanh),
          :(exp), :(exp2), :(expm1), :(log), :(log10), :(log1p),
          :(log2), :(exponent), :(sqrt))
    @eval $(f)(::Missing) = missing
end
clamp(::Missing, lo, hi) = missing

end # module

max_stars_repo_name: sloede/julia

max_issues_repo_name: sloede/julia

max_forks_repo_name: sloede/julia