NVIDIA DRIVE OS Linux SDK API Reference

5.2.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 (12u)
48 
50 #define NVMTENSOR_4D_MAX_N (65536u)
51 
52 #define NVMTENSOR_4D_MAX_C (8192u)
53 
54 #define NVMTENSOR_4D_MAX_H (8192u)
55 
56 #define NVMTENSOR_4D_MAX_W (8192u)
57 
58 #define NVMTENSOR_4D_MAX_X (1024u)
59 
65 #define NVMEDIA_TENSOR_TIMEOUT_INFINITE (0xFFFFFFFFu)
66 
71 typedef struct {
75  uint32_t durationUs;
77 
82 
87 typedef enum {
113 
119 #define NVM_TENSOR_ATTR_CPU_ACCESS_UNCACHED (0x00000001u)
120 
125 #define NVM_TENSOR_ATTR_CPU_ACCESS_CACHED (0x00000002u)
126 
130 #define NVM_TENSOR_ATTR_CPU_ACCESS_UNMAPPED (0x00000003u)
131 
136 #define NVM_TENSOR_ATTR_ALLOC_RESERVED (0x00000010u)
137 
140 #define NVM_TENSOR_ATTR_ALLOC_NONE (0x00000000u)
141 
145 typedef struct {
149  uint32_t value;
151 
156 #define NVM_TENSOR_INIT_ATTR(x) \
157 { \
158  x[0].type = NVM_TENSOR_ATTR_DATA_TYPE; \
159  x[0].value = 0; \
160  \
161  x[1].type = NVM_TENSOR_ATTR_4D_N; \
162  x[1].value = 0; \
163  \
164  x[2].type = NVM_TENSOR_ATTR_4D_C; \
165  x[2].value = 0; \
166  \
167  x[3].type = NVM_TENSOR_ATTR_4D_H; \
168  x[3].value = 0; \
169  \
170  x[4].type = NVM_TENSOR_ATTR_4D_W; \
171  x[4].value = 0; \
172  \
173  x[5].type = NVM_TENSOR_ATTR_4D_X; \
174  x[5].value = 0; \
175  \
176  x[6].type = NVM_TENSOR_ATTR_BITS_PER_ELEMENT; \
177  x[6].value = 0; \
178  \
179  x[7].type = NVM_TENSOR_ATTR_DIMENSION_ORDER; \
180  x[7].value = 0; \
181  \
182  x[8].type = NVM_TENSOR_ATTR_CPU_ACCESS; \
183  x[8].value = 0; \
184  \
185  x[9].type = NVM_TENSOR_ATTR_ALLOC_TYPE; \
186  x[9].value = 0; \
187 }
188 
192 #define NVM_TENSOR_DEFINE_ATTR(x) \
193  NvMediaTensorAttr x[NVM_TENSOR_ATTR_MAX]; \
194  NVM_TENSOR_INIT_ATTR(x); \
195 
196 
218 #define NVM_TENSOR_SET_ATTR_4D(attr, N, C, H, W, order, datatype, bpe, accesstype, alloctype, X)\
219 { \
220  attr[0].type = NVM_TENSOR_ATTR_DATA_TYPE; \
221  attr[0].value = NVM_TENSOR_ATTR_DATA_TYPE_##datatype; \
222  \
223  attr[1].type = NVM_TENSOR_ATTR_4D_N; \
224  attr[1].value = N; \
225  \
226  attr[2].type = NVM_TENSOR_ATTR_4D_C; \
227  attr[2].value = C; \
228  \
229  attr[3].type = NVM_TENSOR_ATTR_4D_H; \
230  attr[3].value = H; \
231  \
232  attr[4].type = NVM_TENSOR_ATTR_4D_W; \
233  attr[4].value = W; \
234  \
235  attr[5].type = NVM_TENSOR_ATTR_4D_X; \
236  attr[5].value = X; \
237  \
238  attr[6].type = NVM_TENSOR_ATTR_BITS_PER_ELEMENT; \
239  attr[6].value = NVM_TENSOR_ATTR_BITS_PER_ELEMENT_##bpe; \
240  \
241  attr[7].type = NVM_TENSOR_ATTR_DIMENSION_ORDER; \
242  attr[7].value = NVM_TENSOR_ATTR_DIMENSION_ORDER_##order; \
243  \
244  attr[8].type = NVM_TENSOR_ATTR_CPU_ACCESS; \
245  attr[8].value = NVM_TENSOR_ATTR_CPU_ACCESS_##accesstype; \
246  \
247  attr[9].type = NVM_TENSOR_ATTR_ALLOC_TYPE; \
248  attr[9].value = NVM_TENSOR_ATTR_ALLOC_##alloctype; \
249 }
250 
255 typedef enum {
263 
271 typedef struct {
273  uint32_t size;
275  void *mapping;
277 
284 void
286  NvMediaTensor *tensor
287 );
288 
313  NvMediaTensor *tensor,
314  NvMediaTensorLockAccess lockAccessType,
315  NvMediaTensorSurfaceMap *surfaceMap
316 );
317 
326 void
328  NvMediaTensor *tensor
329 );
330 
347  NvMediaTensor *tensor,
348  uint32_t millisecondWait,
350 );
351 
365  const NvMediaTensor *tensor,
366  NvMediaTensorMetaData *tensormetadata
367 );
368 
381  NvMediaVersion *version
382 );
383 
386 /*
387  * \defgroup history_nvmedia_tensor History
388  * Provides change history for the NvMedia Tensor API.
389  *
390  * \section history_nvmedia_tensor Version History
391  *
392  * <b> Version 1.0 </b> May 22, 2017
393  * - Initial release
394  *
395  * <b> Version 1.2 </b> Jun 21, 2019
396  * - Fix Minor Misra Violations
397  *
398  * <b> Version 1.3 </b> Jun 22, 2019
399  * - Deprecate the NvMediaTensorCreate API
400  * in support of NvSciBuf APIs
401  *
402  * <b> Version 1.4 </b> Dec 9, 2019
403  * - Add const to NvMediaGetTensorMetaData
404  * in support of Misra rule 8.13
405  *
406  * <b> Version 1.5 </b> Jan 10, 2020
407  * - In NvMediaTensorLock API fix data type of
408  * lockAccessType parameter
409  *
410  * <b> Version 1.6 </b> Jan 15, 2020
411  * - Fix the comments for: NvMediaTensorGetMetaData,
412  * NvMediaTensorGetStatus, NvMediaTensorLock
413  *
414  * <b> Version 1.7 </b> Feb 13, 2020
415  * - Fix the comments for: NvMediaTensorLock,
416  * NvMediaTensorGetStatus, NvMediaTensorGetMetaData
417  * - Rearranged NvMediaTensorDestroy
418  *
419  * <b> Version 1.8 </b> Mar 25, 2020
420  * - Fix the doxygen comments for most functions
421  * - Fixed NvMediaTensorDestroy misra violation 8.3
422  *
423  * <b> Version 1.9 </b> Apr 14, 2020
424  * - Updated Doxygen comments for enums, macros and structs
425  *
426  * <b> Version 1.10 </b> May 7, 2020
427  * - Updated Doxygen comments for NvMediaTensor struct
428  *
429  * <b> Version 1.11 </b> June 5, 2020
430  * - Added NvMediaTensorGetVersion API
431  *
432  * <b> Version 1.12 </b> June 17, 2020
433  * - Added Max Tensor dimension macros
434  *
435  **/
438 #ifdef __cplusplus
439 }; /* extern "C" */
440 #endif
441 
442 #endif /* NVMEDIA_TENSOR_H */
NvMediaTensorGetVersion
NvMediaStatus NvMediaTensorGetVersion(NvMediaVersion *version)
Returns version information for the NvMediaTensor library.
NvMediaTensorTaskStatus
Holds the status of the latest operation for a tensor.
Definition: nvmedia_tensor.h:71
NVM_TENSOR_ATTR_4D_W
@ NVM_TENSOR_ATTR_4D_W
Defines the width of a 4D tensor.
Definition: nvmedia_tensor.h:107
nvmedia_tensormetadata.h
NVIDIA Media Interface: Tensor Metadata Interface
NVMEDIA_TENSOR_ACCESS_WRITE
@ NVMEDIA_TENSOR_ACCESS_WRITE
Write access.
Definition: nvmedia_tensor.h:259
NvMediaTensorAttr::type
NvMediaTensorAttrType type
Holds tensor creation attribute type.
Definition: nvmedia_tensor.h:147
NvMediaTensorSurfaceMap
Defines the tensor surface map descriptor used by NvMediaTensorLock().
Definition: nvmedia_tensor.h:271
NvMediaTensorSurfaceMap::size
uint32_t size
Total size of the tensor.
Definition: nvmedia_tensor.h:273
NvMediaTensorLockAccess
NvMediaTensorLockAccess
Defines tensor lock access types.
Definition: nvmedia_tensor.h:255
NvMediaTensorAttrType
NvMediaTensorAttrType
Defines attribute types for creating NvMedia Tensor.
Definition: nvmedia_tensor.h:87
NVM_TENSOR_ATTR_CPU_ACCESS
@ NVM_TENSOR_ATTR_CPU_ACCESS
Defines the CPU access to tensor.
Definition: nvmedia_tensor.h:95
NvMediaTensorTaskStatus::durationUs
uint32_t durationUs
Duration of the operation in microseconds.
Definition: nvmedia_tensor.h:75
NvMediaTensorLock
NvMediaStatus NvMediaTensorLock(NvMediaTensor *tensor, NvMediaTensorLockAccess lockAccessType, NvMediaTensorSurfaceMap *surfaceMap)
Locks a tensor and returns the associated mapped pointers pointing to the tensor surface data.
NvMediaVersion
Holds NvMedia version information.
Definition: nvmedia_core.h:237
NVM_TENSOR_ATTR_BITS_PER_ELEMENT
@ NVM_TENSOR_ATTR_BITS_PER_ELEMENT
Defines the tensor bits per element.
Definition: nvmedia_tensor.h:91
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:93
NvMediaTensor
struct NvMediaTensor NvMediaTensor
A handle representing tensor objects.
Definition: nvmedia_tensor.h:81
NVM_TENSOR_ATTR_4D_C
@ NVM_TENSOR_ATTR_4D_C
Defines the number of channels of a 4D tensor.
Definition: nvmedia_tensor.h:103
NVM_TENSOR_ATTR_MAX
@ NVM_TENSOR_ATTR_MAX
Defines the maximum number of tensor creation attributes.
Definition: nvmedia_tensor.h:111
NVMEDIA_TENSOR_ACCESS_READ
@ NVMEDIA_TENSOR_ACCESS_READ
Read access.
Definition: nvmedia_tensor.h:257
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:275
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.
Definition: nvmedia_tensor.h:97
NVM_TENSOR_ATTR_4D_X
@ NVM_TENSOR_ATTR_4D_X
Defines the x value of a 4D tensor.
Definition: nvmedia_tensor.h:109
NvMediaTensorAttr
Holds tensor creation attributes.
Definition: nvmedia_tensor.h:145
NVM_TENSOR_ATTR_DATA_TYPE
@ NVM_TENSOR_ATTR_DATA_TYPE
Specifies the tensor data type.
Definition: nvmedia_tensor.h:89
NVMEDIA_TENSOR_ACCESS_READ_WRITE
@ NVMEDIA_TENSOR_ACCESS_READ_WRITE
Read/Write access.
Definition: nvmedia_tensor.h:261
NvMediaTensorMetaData
Holds the tensor metadata.
Definition: nvmedia_tensormetadata.h:423
NVM_TENSOR_ATTR_4D_H
@ NVM_TENSOR_ATTR_4D_H
Defines the height of a 4D tensor.
Definition: nvmedia_tensor.h:105
NvMediaTensorUnlock
void NvMediaTensorUnlock(NvMediaTensor *tensor)
Unlocks a tensor.
NvMediaTensorAttr::value
uint32_t value
Holds tensor creation attribute value.
Definition: nvmedia_tensor.h:149
NvMediaTensorTaskStatus::status
NvMediaStatus status
Holds the return status of the operation as an error code of type - NvMediaStatus.
Definition: nvmedia_tensor.h:73
NvMediaTensorDestroy
void NvMediaTensorDestroy(NvMediaTensor *tensor)
Destroys a tensor object previously created by NvMediaTensorCreateFromNvSciBuf().
NVM_TENSOR_ATTR_4D_N
@ NVM_TENSOR_ATTR_4D_N
Attribute types for 4D tensors.
Definition: nvmedia_tensor.h:101