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
108 lines
2.6 KiB
C++
108 lines
2.6 KiB
C++
/*
|
|
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include <hip/hip_runtime.h>
|
|
#include <iostream>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <string>
|
|
#ifdef _WIN32
|
|
#include <windows.h>
|
|
#else
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#endif
|
|
|
|
// Generic helper executable to test environment variables with HIP runtime
|
|
// AMD-only: Tests GPU_ENABLE_PAL (ROCr vs PAL backend selection)
|
|
//
|
|
#ifndef __HIP_PLATFORM_AMD__
|
|
#error "This test is AMD-only (GPU_ENABLE_PAL controls ROCr vs PAL backend)"
|
|
#endif
|
|
|
|
static int setEnvironmentVariable(const char* name, const char* value) {
|
|
#ifdef _WIN32
|
|
return _putenv_s(name, value);
|
|
#else
|
|
return setenv(name, value, 1);
|
|
#endif
|
|
}
|
|
|
|
static int unsetEnvironmentVariable(const char* name) {
|
|
#ifdef _WIN32
|
|
return _putenv_s(name, "");
|
|
#else
|
|
return unsetenv(name);
|
|
#endif
|
|
}
|
|
|
|
// Initialize HIP with AMD_LOG_LEVEL=7, then restore original log level
|
|
static int initializeHIP() {
|
|
const char* originalLogLevel = getenv("AMD_LOG_LEVEL");
|
|
std::string savedLogLevel;
|
|
if (originalLogLevel) {
|
|
savedLogLevel = originalLogLevel;
|
|
}
|
|
|
|
setEnvironmentVariable("AMD_LOG_LEVEL", "7");
|
|
|
|
int deviceCount = 0;
|
|
hipError_t err = hipGetDeviceCount(&deviceCount);
|
|
|
|
if (!savedLogLevel.empty()) {
|
|
setEnvironmentVariable("AMD_LOG_LEVEL", savedLogLevel.c_str());
|
|
} else {
|
|
unsetEnvironmentVariable("AMD_LOG_LEVEL");
|
|
}
|
|
|
|
if (err != hipSuccess) {
|
|
std::cerr << "ERROR: hipGetDeviceCount failed: " << hipGetErrorString(err) << std::endl;
|
|
return 255;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// Test GPU_ENABLE_PAL - logs which backend initialized
|
|
static int checkGpuEnablePal(const char* value) {
|
|
return initializeHIP();
|
|
}
|
|
|
|
// Test generic environment variable
|
|
static int testEnvironmentVariable(const std::string& envName, const char* value) {
|
|
return initializeHIP();
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
if (argc != 3) {
|
|
std::cerr << "Usage: " << argv[0] << " <env_var_name> <env_var_value>" << std::endl;
|
|
return 255;
|
|
}
|
|
|
|
const std::string envName = argv[1];
|
|
const char* envValue = argv[2];
|
|
|
|
// Handle special "UNSET" marker to test default behavior
|
|
if (strcmp(envValue, "UNSET") == 0) {
|
|
unsetEnvironmentVariable(envName.c_str());
|
|
} else {
|
|
// Set the environment variable
|
|
if (setEnvironmentVariable(envName.c_str(), envValue) != 0) {
|
|
std::cerr << "ERROR: Failed to set " << envName << std::endl;
|
|
return 255;
|
|
}
|
|
}
|
|
|
|
// Run the test
|
|
int result;
|
|
if (envName == "GPU_ENABLE_PAL") {
|
|
result = checkGpuEnablePal(envValue);
|
|
} else {
|
|
result = testEnvironmentVariable(envName, envValue);
|
|
}
|
|
|
|
return result;
|
|
}
|