Files
TheRock/rocm-systems/projects/hip-tests/catch/unit/device/getDeviceCount_exe.cc
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

74 lines
1.9 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#include <hip/hip_runtime.h>
#include <iostream>
#include <stdlib.h>
bool UNSETENV(std::string var) {
int result = -1;
#ifdef __unix__
result = unsetenv(var.c_str());
#else
result = _putenv((var + '=').c_str());
#endif
return (result == 0) ? true : false;
}
bool SETENV(std::string var, std::string value) {
int result = -1;
#ifdef __unix__
result = setenv(var.c_str(), value.c_str(), 1);
#else
result = _putenv((var + '=' + value).c_str());
#endif
return (result == 0) ? true : false;
}
// Expects 1 command line arg, which is the Device Visible String
int main(int argc, char** argv) {
if (argc != 2) {
std::cerr << "Invalid number of args passed.\n"
<< "argc : " << argc << std::endl;
for (int i = 0; i < argc; i++) {
std::cerr << " argv[" << i << "] : " << argv[0] << std::endl;
}
std::cerr << "The program expects device visibility string i.e. 0,1,2" << std::endl;
return -1;
}
// disable visible_devices env from shell
#ifdef __HIP_PLATFORM_NVIDIA__
UNSETENV("CUDA_VISIBLE_DEVICES");
SETENV("CUDA_VISIBLE_DEVICES", argv[1]);
auto init_res = hipInit(0);
if (hipSuccess != init_res) {
std::cerr << "CUDA INIT API returned : " << hipGetErrorString(init_res) << std::endl;
return -1;
}
#else
UNSETENV("ROCR_VISIBLE_DEVICES");
UNSETENV("HIP_VISIBLE_DEVICES");
SETENV("ROCR_VISIBLE_DEVICES", argv[1]);
SETENV("HIP_VISIBLE_DEVICES", argv[1]);
#endif
int count = 0;
auto res = hipGetDeviceCount(&count);
if (hipSuccess != res) {
std::cerr << "HIP API returned : " << hipGetErrorString(res) << std::endl;
return -1;
}
#ifdef __HIP_PLATFORM_NVIDIA__
UNSETENV("CUDA_VISIBLE_DEVICES");
#else
UNSETENV("ROCR_VISIBLE_DEVICES");
UNSETENV("HIP_VISIBLE_DEVICES");
#endif
return count;
}