NVIDIA DRIVE OS Linux SDK API Reference

5.1.15.0 Release
For Test and Development only
nvmedia_tensor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 - 2020, NVIDIA CORPORATION. All rights reserved. All
3  * information contained herein is proprietary and confidential to NVIDIA
4  * Corporation. Any use, reproduction, or disclosure without the written
5  * permission of NVIDIA Corporation is prohibited.
6  */
7 
16 #ifndef NVMEDIA_TENSOR_H
17 #define NVMEDIA_TENSOR_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #include "nvmedia_core.h"
24 #include "nvmedia_tensormetadata.h"
25 
45 #define NVMEDIA_TENSOR_VERSION_MAJOR (1u)
46 
47 #define NVMEDIA_TENSOR_VERSION_MINOR (7u)
48 
53 #define NVMEDIA_TENSOR_TIMEOUT_INFINITE (0xFFFFFFFFu)
54 
59 typedef struct {
63  uint32_t durationUs;
65 
70 
74 typedef enum {
99 
103 #define NVM_TENSOR_ATTR_CPU_ACCESS_UNCACHED (0x00000001u)
104 
107 #define NVM_TENSOR_ATTR_CPU_ACCESS_CACHED (0x00000002u)
108 
112 #define NVM_TENSOR_ATTR_CPU_ACCESS_UNMAPPED (0x00000003u)
113 
117 #define NVM_TENSOR_ATTR_ALLOC_RESERVED (0x00000010u)
118 
121 #define NVM_TENSOR_ATTR_ALLOC_NONE (0x00000000u)
122 
126 typedef struct {
130  uint32_t value;
132 
133 
138 #define NVM_TENSOR_INIT_ATTR(x) \
139 { \
140  x[0].type = NVM_TENSOR_ATTR_DATA_TYPE; \
141  x[0].value = 0; \
142  \
143  x[1].type = NVM_TENSOR_ATTR_4D_N; \
144  x[1].value = 0; \
145  \
146  x[2].type = NVM_TENSOR_ATTR_4D_C; \
147  x[2].value = 0; \
148  \
149  x[3].type = NVM_TENSOR_ATTR_4D_H; \
150  x[3].value = 0; \
151  \
152  x[4].type = NVM_TENSOR_ATTR_4D_W; \
153  x[4].value = 0; \
154  \
155  x[5].type = NVM_TENSOR_ATTR_4D_X; \
156  x[5].value = 0; \
157  \
158  x[6].type = NVM_TENSOR_ATTR_BITS_PER_ELEMENT; \
159  x[6].value = 0; \
160  \
161  x[7].type = NVM_TENSOR_ATTR_DIMENSION_ORDER; \
162  x[7].value = 0; \
163  \
164  x[8].type = NVM_TENSOR_ATTR_CPU_ACCESS; \
165  x[8].value = 0; \
166  \
167  x[9].type = NVM_TENSOR_ATTR_ALLOC_TYPE; \
168  x[9].value = 0; \
169 }
170 
174 #define NVM_TENSOR_DEFINE_ATTR(x) \
175  NvMediaTensorAttr x[NVM_TENSOR_ATTR_MAX]; \
176  NVM_TENSOR_INIT_ATTR(x); \
177 
178 
198 #define NVM_TENSOR_SET_ATTR_4D(attr, N, C, H, W, order, datatype, bpe, accesstype, alloctype, X)\
199 { \
200  attr[0].type = NVM_TENSOR_ATTR_DATA_TYPE; \
201  attr[0].value = NVM_TENSOR_ATTR_DATA_TYPE_##datatype; \
202  \
203  attr[1].type = NVM_TENSOR_ATTR_4D_N; \
204  attr[1].value = N; \
205  \
206  attr[2].type = NVM_TENSOR_ATTR_4D_C; \
207  attr[2].value = C; \
208  \
209  attr[3].type = NVM_TENSOR_ATTR_4D_H; \
210  attr[3].value = H; \
211  \
212  attr[4].type = NVM_TENSOR_ATTR_4D_W; \
213  attr[4].value = W; \
214  \
215  attr[5].type = NVM_TENSOR_ATTR_4D_X; \
216  attr[5].value = X; \
217  \
218  attr[6].type = NVM_TENSOR_ATTR_BITS_PER_ELEMENT; \
219  attr[6].value = NVM_TENSOR_ATTR_BITS_PER_ELEMENT_##bpe; \
220  \
221  attr[7].type = NVM_TENSOR_ATTR_DIMENSION_ORDER; \
222  attr[7].value = NVM_TENSOR_ATTR_DIMENSION_ORDER_##order; \
223  \
224  attr[8].type = NVM_TENSOR_ATTR_CPU_ACCESS; \
225  attr[8].value = NVM_TENSOR_ATTR_CPU_ACCESS_##accesstype; \
226  \
227  attr[9].type = NVM_TENSOR_ATTR_ALLOC_TYPE; \
228  attr[9].value = NVM_TENSOR_ATTR_ALLOC_##alloctype; \
229 }
230 
235 typedef enum {
243 
251 typedef struct {
253  uint32_t size;
255  void *mapping;
257 
264 void
266  NvMediaTensor *tensorDesc
267 );
268 
297  NvMediaTensor *tensor,
298  NvMediaTensorLockAccess lockAccessType,
299  NvMediaTensorSurfaceMap *surfaceMap
300 );
301 
310 void
312  NvMediaTensor *tensor
313 );
314 
332  NvMediaTensor *tensor,
333  uint32_t millisecondWait,
335 );
336 
350  const NvMediaTensor *tensor,
351  NvMediaTensorMetaData *tensormetadata
352 );
353 
356 /*
357  * \defgroup history_nvmedia_tensor History
358  * Provides change history for the NvMedia Tensor API.
359  *
360  * \section history_nvmedia_tensor Version History
361  *
362  * <b> Version 1.0 </b> May 22, 2017
363  * - Initial release
364  *
365  * <b> Version 1.2 </b> Jun 21, 2019
366  * - Fix Minor Misra Violations
367  *
368  * <b> Version 1.3 </b> Jun 22, 2019
369  * - Deprecate the NvMediaTensorCreate API
370  * in support of NvSciBuf APIs
371  *
372  * <b> Version 1.4 </b> Dec 9,2019
373  * - Add const to NvMediaGetTensorMetaData
374  * in support of Misra rule 8.13
375  *
376  * <b> Version 1.5 </b> Jan 10,2020
377  * - In NvMediaTensorLock API fix data type of
378  * lockAccessType parameter
379  *
380  * <b> Version 1.6 </b> Jan 15,2020
381  * - Fix the comments for: NvMediaTensorGetMetaData,
382  * NvMediaTensorGetStatus, NvMediaTensorLock
383  *
384  * <b> Version 1.7 </b> Feb 13,2020
385  * - Fix the comments for: NvMediaTensorLock,
386  * NvMediaTensorGetStatus, NvMediaTensorGetMetaData
387  * - Rearranged NvMediaTensorDestroy
388  *
389  **/
392 #ifdef __cplusplus
393 }; /* extern "C" */
394 #endif
395 
396 #endif /* NVMEDIA_TENSOR_H */
NvMediaTensorTaskStatus
Holds the status of the latest operation for a tensor.
Definition: nvmedia_tensor.h:59
NVM_TENSOR_ATTR_4D_W
@ NVM_TENSOR_ATTR_4D_W
Defines the width of a 4D tensor.
Definition: nvmedia_tensor.h:93
nvmedia_tensormetadata.h
NVIDIA Media Interface: Tensor Metadata Interface
NVMEDIA_TENSOR_ACCESS_WRITE
@ NVMEDIA_TENSOR_ACCESS_WRITE
Write access.
Definition: nvmedia_tensor.h:239
NvMediaTensorAttr::type
NvMediaTensorAttrType type
Holds tensor creation attribute type.
Definition: nvmedia_tensor.h:128
NvMediaTensorSurfaceMap
Defines the tensor surface map descriptor used by NvMediaTensorLock().
Definition: nvmedia_tensor.h:251
NvMediaTensorSurfaceMap::size
uint32_t size
Total size of the tensor.
Definition: nvmedia_tensor.h:253
NvMediaTensorLockAccess
NvMediaTensorLockAccess
Defines tensor lock access types.
Definition: nvmedia_tensor.h:235
NvMediaTensorAttrType
NvMediaTensorAttrType
Defines attribute types for creating NvMedia Tensor.
Definition: nvmedia_tensor.h:74
NVM_TENSOR_ATTR_CPU_ACCESS
@ NVM_TENSOR_ATTR_CPU_ACCESS
Defines the CPU access to tensor (default: uncached).
Definition: nvmedia_tensor.h:82
NvMediaTensorTaskStatus::durationUs
uint32_t durationUs
Duration of the operation in microseconds.
Definition: nvmedia_tensor.h:63
NvMediaTensorDestroy
void NvMediaTensorDestroy(NvMediaTensor *tensorDesc)
Destroys a tensor object previously created by NvMediaTensorCreateFromNvSciBuf().
NvMediaTensorLock
NvMediaStatus NvMediaTensorLock(NvMediaTensor *tensor, NvMediaTensorLockAccess lockAccessType, NvMediaTensorSurfaceMap *surfaceMap)
Locks a tensor and returns the associated mapped pointers pointing to the tensor surface data.
NVM_TENSOR_ATTR_BITS_PER_ELEMENT
@ NVM_TENSOR_ATTR_BITS_PER_ELEMENT
Defines the tensor bits per element.
Definition: nvmedia_tensor.h:78
NvMediaTensorGetMetaData
NvMediaStatus NvMediaTensorGetMetaData(const NvMediaTensor *tensor, NvMediaTensorMetaData *tensormetadata)
Fills in the metadata information for the tensor.
NVM_TENSOR_ATTR_DIMENSION_ORDER
@ NVM_TENSOR_ATTR_DIMENSION_ORDER
Defines the tensor dimension order.
Definition: nvmedia_tensor.h:80
NvMediaTensor
struct NvMediaTensor NvMediaTensor
A handle representing tensor objects.
Definition: nvmedia_tensor.h:69
NVM_TENSOR_ATTR_4D_C
@ NVM_TENSOR_ATTR_4D_C
Defines the number of channels of a 4D tensor.
Definition: nvmedia_tensor.h:89
NVM_TENSOR_ATTR_MAX
@ NVM_TENSOR_ATTR_MAX
Defines the maximum number of tensor creation attributes.
Definition: nvmedia_tensor.h:97
NVMEDIA_TENSOR_ACCESS_READ
@ NVMEDIA_TENSOR_ACCESS_READ
Read access.
Definition: nvmedia_tensor.h:237
nvmedia_core.h
NVIDIA Media Interface: Core
NvMediaTensorGetStatus
NvMediaStatus NvMediaTensorGetStatus(NvMediaTensor *tensor, uint32_t millisecondWait, NvMediaTensorTaskStatus *status)
Gets the status of the last operation for the tensor, and optionally waits for the operation to compl...
NvMediaTensorSurfaceMap::mapping
void * mapping
CPU accessible memory pointer of Tensor.
Definition: nvmedia_tensor.h:255
NvMediaStatus
NvMediaStatus
Defines all possible error codes.
Definition: nvmedia_core.h:180
NVM_TENSOR_ATTR_ALLOC_TYPE
@ NVM_TENSOR_ATTR_ALLOC_TYPE
Defines the allocation type, reserved (default: none).
Definition: nvmedia_tensor.h:84
NVM_TENSOR_ATTR_4D_X
@ NVM_TENSOR_ATTR_4D_X
Defines the x value of a 4D tensor.
Definition: nvmedia_tensor.h:95
NvMediaTensorAttr
Holds tensor creation attributes.
Definition: nvmedia_tensor.h:126
NVM_TENSOR_ATTR_DATA_TYPE
@ NVM_TENSOR_ATTR_DATA_TYPE
Specifies the tensor data type.
Definition: nvmedia_tensor.h:76
NVMEDIA_TENSOR_ACCESS_READ_WRITE
@ NVMEDIA_TENSOR_ACCESS_READ_WRITE
Read/Write access.
Definition: nvmedia_tensor.h:241
NvMediaTensorMetaData
Holds the tensor metadata.
Definition: nvmedia_tensormetadata.h:420
NVM_TENSOR_ATTR_4D_H
@ NVM_TENSOR_ATTR_4D_H
Defines the height of a 4D tensor.
Definition: nvmedia_tensor.h:91
NvMediaTensorUnlock
void NvMediaTensorUnlock(NvMediaTensor *tensor)
Unlocks a tensor.
NvMediaTensorAttr::value
uint32_t value
Holds tensor creation attribute value.
Definition: nvmedia_tensor.h:130
NvMediaTensorTaskStatus::status
NvMediaStatus status
Holds actual status - NvMediaStatus.
Definition: nvmedia_tensor.h:61
NVM_TENSOR_ATTR_4D_N
@ NVM_TENSOR_ATTR_4D_N
Attribute types for 4D tensors.
Definition: nvmedia_tensor.h:87