NVIDIA DRIVE OS Linux SDK API Reference

5.1.6.0 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nvrm_gpu.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2018 NVIDIA Corporation. All rights reserved.
3  *
4  * NVIDIA Corporation and its licensors retain all intellectual property
5  * and proprietary rights in and to this software, related documentation
6  * and any modifications thereto. Any use, reproduction, disclosure or
7  * distribution of this software and related documentation without an express
8  * license agreement from NVIDIA Corporation is strictly prohibited.
9  */
10 
11 #ifndef INCLUDED_nvrm_gpu_H
12 #define INCLUDED_nvrm_gpu_H
13 
14 #include <stdbool.h>
15 #include <stdint.h>
16 #include <stddef.h>
17 
18 #include "nvcommon.h"
19 #include "nverror.h"
20 
21 #if defined(__cplusplus)
22 extern "C"
23 {
24 #endif
25 
81 typedef struct NvRmGpuLibRec NvRmGpuLib;
83 typedef struct NvRmGpuDeviceRec NvRmGpuDevice;
84 
85 /**** Generic functions ****/
86 
87 typedef struct NvRmGpuLibOpenAttrRec
88 {
89  // placeholder for extensions
90  uint32_t reserved;
91 
93 
94 #define NVRM_GPU_DEFINE_LIB_OPEN_ATTR(x) \
95  NvRmGpuLibOpenAttr x = { 0 }
96 
102 
109 NvError NvRmGpuLibClose(NvRmGpuLib *hlib);
110 
111 typedef enum
112 {
116 
118 {
121  const char *name; // temporary name, e.g., Nouveau GPU 0 or some such
123 
139 const NvRmGpuLibDeviceListEntry *NvRmGpuLibListDevices(NvRmGpuLib *hlib, size_t *pnumDevices);
140 
148 NvError NvRmGpuLibAttachDevice(NvRmGpuLib *const hlib, const int deviceIndex);
149 
157 NvError NvRmGpuLibDetachDevice(NvRmGpuLib *const hlib, const int deviceIndex);
158 
159 /**** Device functions ****/
160 
161 #define NVRM_GPU_DEVICE_INDEX_DEFAULT (-1)
162 
163 typedef enum
164 {
165  NvRmGpuSyncType_Default, // platform-specific default
169 
171 {
180 
189 
190 #define NVRM_GPU_DEFINE_DEVICE_OPEN_ATTR(x) \
191  NvRmGpuDeviceOpenAttr x = { NvRmGpuSyncType_Default, false }
192 
193 
203 NvError NvRmGpuDeviceOpen(NvRmGpuLib *hLib, int deviceIndex, const NvRmGpuDeviceOpenAttr *attr,
204  NvRmGpuDevice **phDevice);
205 
212 NvError NvRmGpuDeviceClose(NvRmGpuDevice *hDevice);
213 
241 #if NVOS_IS_LINUX || NVOS_IS_QNX
242 #define NVRM_GPU_CLOCK_ASYNC_REQ_HANDLE_PRIFMT "d"
243 typedef int NvRmGpuClockAsyncReqHandle;
244 #else
245 #define NVRM_GPU_CLOCK_ASYNC_REQ_HANDLE_PRIFMT "p"
246 typedef struct NvRmGpuClockAsyncNotImplemented *NvRmGpuClockAsyncReqHandle;
247 #endif
248 
252 typedef enum NvRmGpuClockDomain
253 {
258 
259 typedef enum NvRmGpuClockType
260 {
265 
267 {
270  uint64_t freqHz;
272 
274 {
276  uint64_t freqHz;
278 
279 typedef struct NvRmGpuClockRangeRec
280 {
281  uint64_t minHz;
282  uint64_t maxHz;
284 
285 typedef struct NvRmGpuClockPointRec
286 {
287  uint64_t freqHz;
289 
291 {
294  size_t maxVfPoints;
296 
307 NvError NvRmGpuClockGetDomains(NvRmGpuDevice *hDevice,
308  const NvRmGpuClockDomainInfo **infos,
309  size_t *pNumDomains);
310 
326 NvError NvRmGpuClockGetPoints(NvRmGpuDevice *hDevice,
327  NvRmGpuClockDomain domain,
328  NvRmGpuClockPoint *pClkPoints,
329  size_t *pNumPoints);
330 
366 NvError NvRmGpuClockSet(NvRmGpuDevice *hDevice,
367  const NvRmGpuClockSetEntry *pClkSetEntries,
368  size_t numEntries,
369  NvRmGpuClockAsyncReqHandle *phReq);
370 
386 NvError NvRmGpuClockWaitAsyncReq(NvRmGpuDevice *hDevice,
387  const NvRmGpuClockAsyncReqHandle *phReqs,
388  size_t numEntries,
389  uint32_t timeoutMs);
390 
403  NvRmGpuClockAsyncReqHandle hReq);
404 
418 NvError NvRmGpuClockWaitAnyEvent(NvRmGpuDevice *hDevice,
419  uint32_t timeoutMs);
420 
433 NvError NvRmGpuClockGet(NvRmGpuDevice *hDevice,
434  NvRmGpuClockGetEntry *pClkGetEntries,
435  size_t numEntries);
436 
445 NvError NvRmGpuDeviceGetLoad(NvRmGpuDevice *hDevice,
446  uint32_t *pLoadPerMille);
447 
448 typedef enum
449 {
454 
466  const NvRmGpuDeviceVoltage **pSensors,
467  size_t *numSensors);
477 NvError NvRmGpuDeviceGetVoltage(NvRmGpuDevice *hDevice,
478  NvRmGpuDeviceVoltage which,
479  uint64_t *pVoltageMicroVolt);
480 
481 typedef enum
482 {
485 
497  const NvRmGpuDeviceCurrent **pSensors,
498  size_t *numSensors);
499 
509 NvError NvRmGpuDeviceGetCurrent(NvRmGpuDevice *hDevice,
510  NvRmGpuDeviceCurrent which,
511  uint64_t *pCurrentMicroAmpere);
512 
513 typedef enum
514 {
515  NvRmGpuDevicePower_Bus = 1 // power consumed at regulator
517 
529  const NvRmGpuDevicePower **pSensors,
530  size_t *numSensors);
531 
541 NvError NvRmGpuDeviceGetPower(NvRmGpuDevice *hDevice,
542  NvRmGpuDevicePower which,
543  uint64_t *pPowerMicroWatt);
544 
545 
546 typedef enum
547 {
550 
562  const NvRmGpuDeviceTemperature **pSensors,
563  size_t *numSensors);
564 
576  int32_t *pTemperatureMilliCelsius);
577 
587  int32_t temperature_mC);
588 
590 typedef enum
591 {
612 
613 typedef struct NvRmGpuDeviceEventSessionRec NvRmGpuDeviceEventSession;
614 
617 {
623 
624 #define NVRM_GPU_DEFINE_DEVICE_EVENT_SESSION_ATTR(x) \
625  NvRmGpuDeviceEventSessionOpenAttr x = { NULL, 0 }
626 
628 {
629  static const NvRmGpuDeviceEventId allEvents[] =
630  {
639  };
640  attr->filterList = allEvents;
641  attr->filterListSize = NV_ARRAY_SIZE(allEvents);
642 }
643 
655  NvRmGpuDeviceEventSession **phSession);
656 
658 {
660  uint64_t timeNs; // GPU timestamp in ns
662 
680  NvRmGpuDeviceEventInfo *pEventInfo,
681  uint32_t timeoutMs);
682 
692 
695 #if defined(__cplusplus)
696 }
697 #endif
698 
699 #if !defined(NV_SDK_BUILD)
700 #include "nvrm_gpu_priv.h"
701 #endif
702 
703 #endif
NvError NvRmGpuDeviceEventSessionOpen(NvRmGpuDevice *hDevice, const NvRmGpuDeviceEventSessionOpenAttr *attr, NvRmGpuDeviceEventSession **phSession)
Opens the session to monitor device events.
struct NvRmGpuDeviceRec NvRmGpuDevice
Device handle type.
Definition: nvrm_gpu.h:83
struct NvRmGpuDeviceEventSessionOpenAttrRec NvRmGpuDeviceEventSessionOpenAttr
Holds the events for which to listen.
Actual clock frequency programmed (including PLL constraints).
Definition: nvrm_gpu.h:262
Main graphics core clock.
Definition: nvrm_gpu.h:255
struct NvRmGpuLibOpenAttrRec NvRmGpuLibOpenAttr
VF update occurred for a clock domain, either because one session changed target frequency or because...
Definition: nvrm_gpu.h:594
NvError NvRmGpuLibDetachDevice(NvRmGpuLib *const hlib, const int deviceIndex)
Detach and power down a GPU.
One clock domain frequency is below target.
Definition: nvrm_gpu.h:596
NvRmGpuDeviceEventId
Holds information about the GPU device event.
Definition: nvrm_gpu.h:590
GPU lost (non-recoverable).
Definition: nvrm_gpu.h:608
const NvRmGpuLibDeviceListEntry * NvRmGpuLibListDevices(NvRmGpuLib *hlib, size_t *pnumDevices)
Returns a pointer to the device array.
NvRmGpuDeviceState
Definition: nvrm_gpu.h:111
NvRmGpuDeviceState deviceState
Definition: nvrm_gpu.h:120
NvError NvRmGpuDeviceGetTemperature(NvRmGpuDevice *hDevice, NvRmGpuDeviceTemperature which, int32_t *pTemperatureMilliCelsius)
Gets the temperature.
NvError NvRmGpuClockGetPoints(NvRmGpuDevice *hDevice, NvRmGpuClockDomain domain, NvRmGpuClockPoint *pClkPoints, size_t *pNumPoints)
Gets VF points for a given clock domain.
NvError NvRmGpuDeviceGetPower(NvRmGpuDevice *hDevice, NvRmGpuDevicePower which, uint64_t *pPowerMicroWatt)
Gets the power consumed by the GPU.
NvRmGpuClockDomain
Clock domains.
Definition: nvrm_gpu.h:252
NvError NvRmGpuDeviceEventSessionRead(NvRmGpuDeviceEventSession *hSession, NvRmGpuDeviceEventInfo *pEventInfo, uint32_t timeoutMs)
Reads detailed event information from the event session.
NvRmGpuDeviceTemperature
Definition: nvrm_gpu.h:546
One clock domain frequency is below local target frequency requested by one session.
Definition: nvrm_gpu.h:598
NvError NvRmGpuDeviceListTemperatureSensors(NvRmGpuDevice *hDevice, const NvRmGpuDeviceTemperature **pSensors, size_t *numSensors)
Gets the list of available temperature sensors.
NvRmGpuClockRange range
Definition: nvrm_gpu.h:293
static void NvRmGpuDeviceEventSessionOpenAttrSetAllEvents(NvRmGpuDeviceEventSessionOpenAttr *attr)
Definition: nvrm_gpu.h:627
struct NvRmGpuDeviceEventSessionRec NvRmGpuDeviceEventSession
Definition: nvrm_gpu.h:613
struct NvRmGpuClockPointRec NvRmGpuClockPoint
NvError NvRmGpuClockGet(NvRmGpuDevice *hDevice, NvRmGpuClockGetEntry *pClkGetEntries, size_t numEntries)
Gets clock state(s).
Memory clock.
Definition: nvrm_gpu.h:254
NvError NvRmGpuDeviceClose(NvRmGpuDevice *hDevice)
Closes the GPU device.
NvError NvRmGpuDeviceGetLoad(NvRmGpuDevice *hDevice, uint32_t *pLoadPerMille)
Gets gpu load.
Target clock frequency requested by application.
Definition: nvrm_gpu.h:261
struct NvRmGpuLibDeviceListEntryRec NvRmGpuLibDeviceListEntry
NvError NvRmGpuDeviceListCurrentSensors(NvRmGpuDevice *hDevice, const NvRmGpuDeviceCurrent **pSensors, size_t *numSensors)
Gets a list of the available current sensors.
NvError NvRmGpuClockWaitAnyEvent(NvRmGpuDevice *hDevice, uint32_t timeoutMs)
Waits on any clock update event.
NvRmGpuDeviceEventId eventId
Definition: nvrm_gpu.h:659
NvError NvRmGpuDeviceListPowerSensors(NvRmGpuDevice *hDevice, const NvRmGpuDevicePower **pSensors, size_t *numSensors)
Gets a list of the available power sensors.
struct NvRmGpuClockGetEntryRec NvRmGpuClockGetEntry
NvError NvRmGpuClockGetDomains(NvRmGpuDevice *hDevice, const NvRmGpuClockDomainInfo **infos, size_t *pNumDomains)
Gets configurable clock domains.
struct NvRmGpuClockRangeRec NvRmGpuClockRange
NvError NvRmGpuClockCloseAsyncReq(NvRmGpuDevice *hDevice, NvRmGpuClockAsyncReqHandle hReq)
Closes an asynchronous request handle.
NvError NvRmGpuClockSet(NvRmGpuDevice *hDevice, const NvRmGpuClockSetEntry *pClkSetEntries, size_t numEntries, NvRmGpuClockAsyncReqHandle *phReq)
Sets a clock request.
const NvRmGpuDeviceEventId * filterList
Holds the events for which to listen.
Definition: nvrm_gpu.h:619
struct NvRmGpuClockDomainInfoRec NvRmGpuClockDomainInfo
NvError NvRmGpuDeviceThermalAlertSetLimit(NvRmGpuDevice *hDevice, int32_t temperature_mC)
Sets the thermal alert limit.
NvRmGpuLib * NvRmGpuLibOpen(const NvRmGpuLibOpenAttr *attr)
Opens a new instance of the library.
struct NvRmGpuDeviceOpenAttrRec NvRmGpuDeviceOpenAttr
NvError NvRmGpuClockWaitAsyncReq(NvRmGpuDevice *hDevice, const NvRmGpuClockAsyncReqHandle *phReqs, size_t numEntries, uint32_t timeoutMs)
Waits for completion of one or more asynchronous requests.
NvRmGpuSyncType
Definition: nvrm_gpu.h:163
NvRmGpuDeviceCurrent
Definition: nvrm_gpu.h:481
struct NvRmGpuLibRec NvRmGpuLib
Library handle type.
Definition: nvrm_gpu.h:81
NvRmGpuDevicePower
Definition: nvrm_gpu.h:513
NvRmGpuDeviceVoltage
Definition: nvrm_gpu.h:448
NvError NvRmGpuDeviceGetVoltage(NvRmGpuDevice *hDevice, NvRmGpuDeviceVoltage which, uint64_t *pVoltageMicroVolt)
Gets the current voltage.
NvRmGpuClockDomain domain
in: Clock domain to query
Definition: nvrm_gpu.h:268
struct NvRmGpuClockSetEntryRec NvRmGpuClockSetEntry
Number of events.
Definition: nvrm_gpu.h:610
NvError NvRmGpuDeviceEventSessionClose(NvRmGpuDeviceEventSession *hSession)
Closes the event session.
NvError NvRmGpuLibClose(NvRmGpuLib *hlib)
Closes the library and releases all resources.
NvRmGpuClockDomain domain
Definition: nvrm_gpu.h:275
NvRmGpuClockType type
in: Frequency type (target, actual or effective)
Definition: nvrm_gpu.h:269
struct NvRmGpuClockAsyncNotImplemented * NvRmGpuClockAsyncReqHandle
Definition: nvrm_gpu.h:246
bool sandboxFriendlyChannels
If true, channels are created in sandbox-friendly manner.
Definition: nvrm_gpu.h:187
NvRmGpuSyncType syncType
The default sync type for all input/output sync objects.
Definition: nvrm_gpu.h:179
NvRmGpuClockType
Definition: nvrm_gpu.h:259
Effective clock, measured from hardware.
Definition: nvrm_gpu.h:263
NvError NvRmGpuLibAttachDevice(NvRmGpuLib *const hlib, const int deviceIndex)
Power up and attach a GPU.
uint64_t freqHz
out: Frequency in Hz
Definition: nvrm_gpu.h:270
NvError NvRmGpuDeviceGetCurrent(NvRmGpuDevice *hDevice, NvRmGpuDeviceCurrent which, uint64_t *pCurrentMicroAmpere)
Gets the current drawn by the GPU.
NvError NvRmGpuDeviceListVoltageSensors(NvRmGpuDevice *hDevice, const NvRmGpuDeviceVoltage **pSensors, size_t *numSensors)
Gets a list of the available voltage sensors.
Holds the events for which to listen.
Definition: nvrm_gpu.h:616
size_t filterListSize
Holds the size of the filter list.
Definition: nvrm_gpu.h:621
Temperature above threshold.
Definition: nvrm_gpu.h:604
NvError NvRmGpuDeviceOpen(NvRmGpuLib *hLib, int deviceIndex, const NvRmGpuDeviceOpenAttr *attr, NvRmGpuDevice **phDevice)
Opens the GPU device.
NvRmGpuClockDomain domain
Definition: nvrm_gpu.h:292
struct NvRmGpuDeviceEventInfoRec NvRmGpuDeviceEventInfo