diff --git a/projects/rocdecode/samples/videoDecodeFork/videodecodefork.cpp b/projects/rocdecode/samples/videoDecodeFork/videodecodefork.cpp index 1a1c86baee..4ccf42b262 100644 --- a/projects/rocdecode/samples/videoDecodeFork/videodecodefork.cpp +++ b/projects/rocdecode/samples/videoDecodeFork/videodecodefork.cpp @@ -144,14 +144,10 @@ int main(int argc, char **argv) { ERR("ERROR: didn't find any GPU!"); return -1; } - if (device_id >= num_devices) { - ERR("ERROR: the requested device_id is not found! "); - return -1; - } - + hip_status = hipGetDeviceProperties(&hip_dev_prop, device_id); if (hip_status != hipSuccess) { - ERR("ERROR: hipGetDeviceProperties for device (" +TOSTR(device_id) + " ) failed! (" + TOSTR(hip_status) + ")" ); + ERR("ERROR: hipGetDeviceProperties for device (" +TOSTR(device_id) + " ) failed! (" + hipGetErrorName(hip_status) + ")" ); return -1; } @@ -164,13 +160,21 @@ int main(int argc, char **argv) { sd = 1; } + int hip_vis_dev_count = 0; + GetEnvVar("HIP_VISIBLE_DEVICES", hip_vis_dev_count); + for (int i = 0; i < n_fork; i++) { std::unique_ptr demuxer(new VideoDemuxer(input_file_path.c_str())); rocDecVideoCodec rocdec_codec_id = AVCodec2RocDecVideoCodec(demuxer->GetCodecID()); - if (device_id % 2 == 0) - v_device_id[i] = (i % 2 == 0) ? device_id : device_id + sd; - else - v_device_id[i] = (i % 2 == 0) ? device_id - sd : device_id; + if (!hip_vis_dev_count) { + if (device_id % 2 == 0) + v_device_id[i] = (i % 2 == 0) ? device_id : device_id + sd; + else + v_device_id[i] = (i % 2 == 0) ? device_id - sd : device_id; + } else { + v_device_id[i] = i % hip_vis_dev_count; + } + std::unique_ptr dec(new RocVideoDecoder(v_device_id[i], mem_type, rocdec_codec_id, b_force_zero_latency, p_crop_rect)); v_demuxer.push_back(std::move(demuxer)); v_viddec.push_back(std::move(dec)); diff --git a/projects/rocdecode/samples/videoDecodePerf/videodecodeperf.cpp b/projects/rocdecode/samples/videoDecodePerf/videodecodeperf.cpp index 4dbdb8a4b3..4079385191 100644 --- a/projects/rocdecode/samples/videoDecodePerf/videodecodeperf.cpp +++ b/projects/rocdecode/samples/videoDecodePerf/videodecodeperf.cpp @@ -147,14 +147,10 @@ int main(int argc, char **argv) { ERR("ERROR: didn't find any GPU!"); return -1; } - if (device_id >= num_devices) { - ERR("ERROR: the requested device_id is not found! "); - return -1; - } hip_status = hipGetDeviceProperties(&hip_dev_prop, device_id); if (hip_status != hipSuccess) { - ERR("ERROR: hipGetDeviceProperties for device (" +TOSTR(device_id) + " ) failed! (" + TOSTR(hip_status) + ")" ); + ERR("ERROR: hipGetDeviceProperties for device (" +TOSTR(device_id) + " ) failed! (" + hipGetErrorName(hip_status) + ")" ); return -1; } @@ -171,13 +167,20 @@ int main(int argc, char **argv) { std::vector> v_viddec; std::vector v_device_id(n_thread); + int hip_vis_dev_count = 0; + GetEnvVar("HIP_VISIBLE_DEVICES", hip_vis_dev_count); + for (int i = 0; i < n_thread; i++) { std::unique_ptr demuxer(new VideoDemuxer(input_file_path.c_str())); rocDecVideoCodec rocdec_codec_id = AVCodec2RocDecVideoCodec(demuxer->GetCodecID()); - if (device_id % 2 == 0) - v_device_id[i] = (i % 2 == 0) ? device_id : device_id + sd; - else - v_device_id[i] = (i % 2 == 0) ? device_id - sd : device_id; + if (!hip_vis_dev_count) { + if (device_id % 2 == 0) + v_device_id[i] = (i % 2 == 0) ? device_id : device_id + sd; + else + v_device_id[i] = (i % 2 == 0) ? device_id - sd : device_id; + } else { + v_device_id[i] = i % hip_vis_dev_count; + } std::unique_ptr dec(new RocVideoDecoder(v_device_id[i], mem_type, rocdec_codec_id, b_force_zero_latency, p_crop_rect)); v_demuxer.push_back(std::move(demuxer)); v_viddec.push_back(std::move(dec)); diff --git a/projects/rocdecode/utils/rocvideodecode/roc_video_dec.cpp b/projects/rocdecode/utils/rocvideodecode/roc_video_dec.cpp index 066fd7e194..95e4a684ce 100644 --- a/projects/rocdecode/utils/rocvideodecode/roc_video_dec.cpp +++ b/projects/rocdecode/utils/rocvideodecode/roc_video_dec.cpp @@ -1078,3 +1078,15 @@ bool RocVideoDecoder::InitHIP(int device_id) { HIP_API_CALL(hipStreamCreate(&hip_stream_)); return true; } + +int GetEnvVar(const char *name, int &dev_count) { + char *v = std::getenv(name); + if (v) { + char* p_tkn = std::strtok(v, ","); + while (p_tkn != nullptr) { + dev_count++; + p_tkn = strtok(nullptr, ","); + } + } + return dev_count; +} diff --git a/projects/rocdecode/utils/rocvideodecode/roc_video_dec.h b/projects/rocdecode/utils/rocvideodecode/roc_video_dec.h index 8de5de15a6..33ac488809 100644 --- a/projects/rocdecode/utils/rocvideodecode/roc_video_dec.h +++ b/projects/rocdecode/utils/rocvideodecode/roc_video_dec.h @@ -33,6 +33,7 @@ THE SOFTWARE. #include #include #include +#include #include extern "C" { #include "libavutil/md5.h" @@ -149,6 +150,8 @@ typedef struct ReconfigParams_t { uint32_t reconfig_flush_mode; } ReconfigParams; +int GetEnvVar(const char *name, int &dev_count); + class RocVideoDecoder { public: /**