I am using nvjpeg to encode a series of pictures into JPEG. The size of each array of bmp is 240 * 240 * 3.
for (int i = 0; i < cur_ti - bat_ti; i+=params.num_threads) {
for (int j = 0; j < params.num_threads; j++) {
auto& per_thread_params = params.enjpeg_per_thread_data[j];
CHECK_CUDA(cudaMemcpyAsync(
imgdesc[i].channel[0],
batch_data + (i + bat_ti) * params.tile_size * params.tile_size * 3,
params.tile_size * params.tile_size * 3,
cudaMemcpyHostToDevice,
per_thread_params.stream));
}
for (int j = 0; j < params.num_threads; j++) {
auto& per_thread_params = params.enjpeg_per_thread_data[j];
CHECK_NVJPEG(nvjpegEncodeImage(
params.nvjpeg_handle,
per_thread_params.nv_enc_state,
per_thread_params.nv_enc_params,
&imgdesc[i],
params.fmt,
params.tile_size,
params.tile_size,
per_thread_params.stream));
}
for (int j = 0; j < params.num_threads; j++) {
auto& per_thread_params = params.enjpeg_per_thread_data[j];
size_t length;
CHECK_NVJPEG(nvjpegEncodeRetrieveBitstream(
params.nvjpeg_handle,
per_thread_params.nv_enc_state,
NULL,
&length,
per_thread_params.stream));
output[i].resize(length);
CHECK_NVJPEG(nvjpegEncodeRetrieveBitstream(
params.nvjpeg_handle,
per_thread_params.nv_enc_state,
(unsigned char*)output[i].data(),
&length,
per_thread_params.stream));
}
}
It seems that the encoding time is too long, and the use of multi stream is ineffective for its acceleration. I tried to use multithreading, but it didn't work. Can I find a way that can be concurrent kernel with the function of nvjpegEncodeImage. This is the function of nvjpeg encoder.
https://docs.nvidia.com/cuda/nvjpeg/index.html#nvjpeg-encode-examples
