Skip to content

Commit

Permalink
Update nvimgcodec header
Browse files Browse the repository at this point in the history
Signed-off-by: Joaquin Anton Guirao <janton@nvidia.com>
  • Loading branch information
jantonguirao committed Dec 30, 2024
1 parent e790b86 commit 9b7f0eb
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 50 deletions.
59 changes: 29 additions & 30 deletions dali/operators/imgcodec/image_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,35 +363,35 @@ class ImageDecoder : public StatelessOperator<Backend> {
backends_.clear();
backends_.reserve(4);
if (nvimgcodec_device_id != NVIMGCODEC_DEVICE_CPU_ONLY) {
backends_.push_back(
nvimgcodecBackend_t{NVIMGCODEC_STRUCTURE_TYPE_BACKEND,
sizeof(nvimgcodecBackend_t),
nullptr,
NVIMGCODEC_BACKEND_KIND_HW_GPU_ONLY,
{NVIMGCODEC_STRUCTURE_TYPE_BACKEND_PARAMS,
sizeof(nvimgcodecBackendParams_t), nullptr, hw_load, false}});
backends_.push_back(
nvimgcodecBackend_t{NVIMGCODEC_STRUCTURE_TYPE_BACKEND,
sizeof(nvimgcodecBackend_t),
nullptr,
NVIMGCODEC_BACKEND_KIND_GPU_ONLY,
{NVIMGCODEC_STRUCTURE_TYPE_BACKEND_PARAMS,
sizeof(nvimgcodecBackendParams_t), nullptr, 1.0f, false}});
backends_.push_back(
nvimgcodecBackend_t{NVIMGCODEC_STRUCTURE_TYPE_BACKEND,
sizeof(nvimgcodecBackend_t),
nullptr,
NVIMGCODEC_BACKEND_KIND_HYBRID_CPU_GPU,
{NVIMGCODEC_STRUCTURE_TYPE_BACKEND_PARAMS,
sizeof(nvimgcodecBackendParams_t), nullptr, 1.0f, false}});
backends_.push_back(nvimgcodecBackend_t{
NVIMGCODEC_STRUCTURE_TYPE_BACKEND,
sizeof(nvimgcodecBackend_t),
nullptr,
NVIMGCODEC_BACKEND_KIND_HW_GPU_ONLY,
{NVIMGCODEC_STRUCTURE_TYPE_BACKEND_PARAMS, sizeof(nvimgcodecBackendParams_t), nullptr,
hw_load, NVIMGCODEC_LOAD_HINT_POLICY_FIXED}});
backends_.push_back(nvimgcodecBackend_t{
NVIMGCODEC_STRUCTURE_TYPE_BACKEND,
sizeof(nvimgcodecBackend_t),
nullptr,
NVIMGCODEC_BACKEND_KIND_GPU_ONLY,
{NVIMGCODEC_STRUCTURE_TYPE_BACKEND_PARAMS, sizeof(nvimgcodecBackendParams_t), nullptr,
1.0f, NVIMGCODEC_LOAD_HINT_POLICY_FIXED}});
backends_.push_back(nvimgcodecBackend_t{
NVIMGCODEC_STRUCTURE_TYPE_BACKEND,
sizeof(nvimgcodecBackend_t),
nullptr,
NVIMGCODEC_BACKEND_KIND_HYBRID_CPU_GPU,
{NVIMGCODEC_STRUCTURE_TYPE_BACKEND_PARAMS, sizeof(nvimgcodecBackendParams_t), nullptr,
1.0f, NVIMGCODEC_LOAD_HINT_POLICY_FIXED}});
}
backends_.push_back(
nvimgcodecBackend_t{NVIMGCODEC_STRUCTURE_TYPE_BACKEND,
sizeof(nvimgcodecBackend_t),
nullptr,
NVIMGCODEC_BACKEND_KIND_CPU_ONLY,
{NVIMGCODEC_STRUCTURE_TYPE_BACKEND_PARAMS,
sizeof(nvimgcodecBackendParams_t), nullptr, 1.0f, false}});
backends_.push_back(nvimgcodecBackend_t{
NVIMGCODEC_STRUCTURE_TYPE_BACKEND,
sizeof(nvimgcodecBackend_t),
nullptr,
NVIMGCODEC_BACKEND_KIND_CPU_ONLY,
{NVIMGCODEC_STRUCTURE_TYPE_BACKEND_PARAMS, sizeof(nvimgcodecBackendParams_t), nullptr, 1.0f,
NVIMGCODEC_LOAD_HINT_POLICY_FIXED}});

exec_params_.backends = backends_.data();
exec_params_.num_backends = backends_.size();
Expand Down Expand Up @@ -804,7 +804,7 @@ class ImageDecoder : public StatelessOperator<Backend> {
CHECK_NVIMGCODEC(nvimgcodecFutureDestroy(future));
}
if (decode_status_size != nsamples_decode)
throw std::runtime_error("Failed to run hardware decoder");
throw std::runtime_error("Failed to run decoder");
for (size_t idx = 0; idx < nsamples_decode; idx++) {
size_t orig_idx = decode_sample_idxs_[idx];
auto st_ptr = state_[orig_idx].get();
Expand All @@ -813,7 +813,6 @@ class ImageDecoder : public StatelessOperator<Backend> {
input.GetMeta(orig_idx).GetSourceInfo()));
}
}

if (any_need_processing) {
for (size_t idx = 0; idx < nsamples_decode; idx++) {
size_t orig_idx = decode_sample_idxs_[idx];
Expand Down
51 changes: 31 additions & 20 deletions third_party/nvimgcodec/include/nvimgcodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,18 @@ extern "C"
NVIMGCODEC_BACKEND_KIND_HW_GPU_ONLY = 4, /**< Decoding/encoding is executed on GPU dedicated hardware engine. */
} nvimgcodecBackendKind_t;

/**
* @brief Defines how to interpret the load hint parameter.
*/
typedef enum
{
NVIMGCODEC_LOAD_HINT_POLICY_IGNORE = 1, /**< Load hint is not taken into account. */
NVIMGCODEC_LOAD_HINT_POLICY_FIXED = 2, /**< Load hint is used to calculate the backend batch size once */
NVIMGCODEC_LOAD_HINT_POLICY_ADAPTIVE_MINIMIZE_IDLE_TIME =
3, /**< Load hint is used as an initial hint, and it is recalculated on every iteration to reduce the idle time of threads */
} nvimgcodecLoadHintPolicy_t;


/**
* @brief Defines decoding/encoding backend parameters.
*/
Expand All @@ -576,15 +588,16 @@ extern "C"
void* struct_next; /**< Is NULL or a pointer to an extension structure type. */

/**
* Fraction of the batch items that will be picked by this backend.
* The remaining items will be marked as "saturated" status and will be picked by the next backend.
* This is just a hint and a particular implementation can choose to ignore it. */
* Hint to calculate the fraction of the batch items that will be picked by this backend.
* This is just a hint and a particular implementation can choose to ignore it.
* Different policies can be selected, see `nvimgcodecLoadHintPolicy_t`
*/
float load_hint;

/**
* If true, the backend load will be adapted on every iteration to minize idle time of the threads.
*/
bool adaptive_load;
nvimgcodecLoadHintPolicy_t load_hint_policy;
} nvimgcodecBackendParams_t;

/**
Expand Down Expand Up @@ -1152,36 +1165,36 @@ extern "C"
nvimgcodecStatus_t (*destroy)(nvimgcodecEncoder_t encoder);

/**
* @brief Checks whether decoder can encode given image to code stream with provided parameters.
* @brief Checks whether encoder can encode given image to code stream with provided parameters.
*
* @param encoder [in] Encoder handle.
* @param code_stream [in] Encoded stream.
* @param info [in] Image information, including requested format.
* @param image [in] Image descriptor.
* @param params [in] Encode parameters which will be used with check.
* @param thread_idx [in] Index of the caller thread (can be from 0 to the executor's number of threads, or -1 for non-threaded execution)
* @return nvimgcodecProcessingStatus_t - Processing status
*/
nvimgcodecProcessingStatus_t (*canEncode)(
nvimgcodecEncoder_t encoder,
const nvimgcodecCodeStreamDesc_t* code_stream,
const nvimgcodecImageInfo_t* info,
const nvimgcodecImageDesc_t* image,
const nvimgcodecEncodeParams_t* params,
int thread_idx);

/**
* @brief Encode given image to code stream with provided parameters.
*
* @param encoder [in] Encoder handle.
* @param info [in] Image information, including requested format and output buffer.
** @param image [in] Image descriptor.
* @param code_stream [in] Encoded stream.
* @param params [in] Encode parameters.
* @param thread_idx [in] Index of the caller thread (can be from 0 to the executor's number of threads, or -1 for non-threaded execution)
* @return nvimgcodecProcessingStatus_t - Processing status
*/
nvimgcodecProcessingStatus_t (*encodeSample)(
nvimgcodecStatus_t (*encode)(
nvimgcodecEncoder_t encoder,
const nvimgcodecCodeStreamDesc_t* code_stream,
const nvimgcodecImageInfo_t* info,
const nvimgcodecImageDesc_t* image,
const nvimgcodecEncodeParams_t* params,
int thread_idx);
} nvimgcodecEncoderDesc_t;
Expand Down Expand Up @@ -1229,11 +1242,11 @@ extern "C"
* @param code_stream [in] Encoded stream.
* @param params [in] Decode parameters which will be used with check.
* @param thread_idx [in] Index of the caller thread (can be from 0 to the executor's number of threads, or -1 for non-threaded execution)
* @return nvimgcodecProcessingStatus_t - Processing status
* @return nvimgcodecStatus_t
*/
nvimgcodecProcessingStatus_t (*canDecode)(
nvimgcodecDecoder_t decoder,
const nvimgcodecImageInfo_t* info,
const nvimgcodecImageDesc_t* image,
const nvimgcodecCodeStreamDesc_t* code_stream,
const nvimgcodecDecodeParams_t* params,
int thread_idx);
Expand All @@ -1242,24 +1255,23 @@ extern "C"
* @brief Decode given code stream to image with provided parameters.
*
* @param decoder [in] Decoder handle to use for decoding.
* @param info [in] Image information, including requested format and output buffer.
* @param image [in/out] Image descriptor.
* @param code_stream [in] Encoded stream.
* @param params [in] Decode parameters.
* @param thread_idx [in] Index of the caller thread (can be from 0 to the executor's number of threads, or -1 for non-threaded execution)
* @return nvimgcodecProcessingStatus_t - Processing status
* @return nvimgcodecStatus_t
*/
nvimgcodecProcessingStatus_t (*decodeSample)(
nvimgcodecStatus_t (*decode)(
nvimgcodecDecoder_t decoder,
const nvimgcodecImageInfo_t* info,
const nvimgcodecImageDesc_t* image,
const nvimgcodecCodeStreamDesc_t* code_stream,
const nvimgcodecDecodeParams_t* params,
int thread_idx);

/**
* @brief Decode given batch of code streams to images with provided parameters.
* @param processing_status Pointer to array of batch size of processing statuses.
* @param decoder [in] Decoder handle to use for decoding.
* @param infos [in/out] Pointer to array of batch size of pointers with output image info.
* @param images [in/out] Pointer to array of pointers of batch size with image descriptors.
* @param code_streams [in] Pointer to array of batch size of pointers to encoded stream instances.
* @param batch_size [in] Number of items in batch to decode.
* @param params [in] Decode parameters.
Expand All @@ -1268,8 +1280,7 @@ extern "C"
*/
nvimgcodecStatus_t (*decodeBatch)(
nvimgcodecDecoder_t decoder,
nvimgcodecProcessingStatus_t* processing_status,
const nvimgcodecImageInfo_t** infos,
const nvimgcodecImageDesc_t** images,
const nvimgcodecCodeStreamDesc_t** code_streams,
int batch_size,
const nvimgcodecDecodeParams_t* params,
Expand Down

0 comments on commit 9b7f0eb

Please sign in to comment.