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
151 lines
4.8 KiB
C++
151 lines
4.8 KiB
C++
/*
|
|
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include <hip_test_common.hh>
|
|
#include <hip/hip_runtime_api.h>
|
|
|
|
/**
|
|
* @addtogroup hipDeviceReset hipDeviceReset
|
|
* @{
|
|
* @ingroup DeviceTest
|
|
* `hipDeviceReset(void)` -
|
|
* The state of current device is discarded and updated to a fresh state.
|
|
*
|
|
* Calling this function deletes all streams created, memory allocated, kernels running, events
|
|
* created. Make sure that no other thread is using the device or streams, memory, kernels, events
|
|
* associated with the current device.
|
|
*/
|
|
|
|
/**
|
|
* Test Description
|
|
* ------------------------
|
|
* - Validates that device reset frees allocated memory and
|
|
* reverts modified flags and configs to its default values.
|
|
* Test source
|
|
* ------------------------
|
|
* - unit/device/hipDeviceReset.cc
|
|
* Test requirements
|
|
* ------------------------
|
|
* - HIP_VERSION >= 5.2
|
|
*/
|
|
HIP_TEST_CASE(Unit_hipDeviceReset_Positive_Basic) {
|
|
const auto device = GENERATE(range(0, HipTest::getDeviceCount()));
|
|
HIP_CHECK(hipSetDevice(device));
|
|
|
|
INFO("Current device is: " << device);
|
|
HIP_CHECK(hipDeviceReset());
|
|
|
|
unsigned int flags_before = 0u;
|
|
HIP_CHECK(hipGetDeviceFlags(&flags_before));
|
|
hipSharedMemConfig mem_config_before;
|
|
HIP_CHECK(hipDeviceGetSharedMemConfig(&mem_config_before));
|
|
|
|
void* ptr = nullptr;
|
|
HIP_CHECK(hipMalloc(&ptr, 500));
|
|
|
|
const auto cache_config_ret = hipDeviceSetCacheConfig(hipFuncCachePreferL1);
|
|
REQUIRE((cache_config_ret == hipSuccess || cache_config_ret == hipErrorNotSupported));
|
|
|
|
const auto shared_mem_config_ret = hipDeviceSetSharedMemConfig(
|
|
mem_config_before == hipSharedMemBankSizeFourByte ? hipSharedMemBankSizeEightByte
|
|
: hipSharedMemBankSizeFourByte);
|
|
REQUIRE((shared_mem_config_ret == hipSuccess || shared_mem_config_ret == hipErrorNotSupported));
|
|
|
|
HIP_CHECK(hipSetDeviceFlags(hipDeviceScheduleBlockingSync));
|
|
|
|
HIP_CHECK(hipDeviceReset());
|
|
|
|
unsigned int flags_after = 0u;
|
|
CHECK(hipGetDeviceFlags(&flags_after) == hipSuccess);
|
|
CHECK(flags_after == flags_before);
|
|
|
|
// This will faill in ASAN due to how we handle free
|
|
#if !defined(ENABLE_ADDRESS_SANITIZER)
|
|
CHECK(hipFree(ptr) == hipErrorInvalidValue);
|
|
#endif
|
|
|
|
if (cache_config_ret == hipSuccess) {
|
|
hipFuncCache_t cache_config;
|
|
CHECK(hipDeviceGetCacheConfig(&cache_config) == hipSuccess);
|
|
CHECK(cache_config == hipFuncCachePreferNone);
|
|
}
|
|
|
|
if (shared_mem_config_ret == hipSuccess) {
|
|
hipSharedMemConfig mem_config_after;
|
|
CHECK(hipDeviceGetSharedMemConfig(&mem_config_after) == hipSuccess);
|
|
CHECK(mem_config_after == mem_config_before);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Test Description
|
|
* ------------------------
|
|
* - Resets device from another thread
|
|
* - Validates that device reset frees allocated memory from the main
|
|
* thread, and reverts modified flags and configs to its default values.
|
|
* Test source
|
|
* ------------------------
|
|
* - unit/device/hipDeviceReset.cc
|
|
* Test requirements
|
|
* ------------------------
|
|
* - HIP_VERSION >= 5.2
|
|
*/
|
|
HIP_TEST_CASE(Unit_hipDeviceReset_Positive_Threaded) {
|
|
HIP_CHECK(hipSetDevice(0));
|
|
INFO("Current device is: " << 0);
|
|
HIP_CHECK(hipDeviceReset());
|
|
|
|
unsigned int flags_before = 0u;
|
|
HIP_CHECK(hipGetDeviceFlags(&flags_before));
|
|
hipSharedMemConfig mem_config_before;
|
|
HIP_CHECK(hipDeviceGetSharedMemConfig(&mem_config_before));
|
|
|
|
void* ptr = nullptr;
|
|
HIP_CHECK(hipMalloc(&ptr, 500));
|
|
|
|
const auto cache_config_ret = hipDeviceSetCacheConfig(hipFuncCachePreferL1);
|
|
REQUIRE((cache_config_ret == hipSuccess || cache_config_ret == hipErrorNotSupported));
|
|
|
|
const auto shared_mem_config_ret = hipDeviceSetSharedMemConfig(
|
|
mem_config_before == hipSharedMemBankSizeFourByte ? hipSharedMemBankSizeEightByte
|
|
: hipSharedMemBankSizeFourByte);
|
|
REQUIRE((shared_mem_config_ret == hipSuccess || shared_mem_config_ret == hipErrorNotSupported));
|
|
|
|
|
|
HIP_CHECK(hipSetDeviceFlags(hipDeviceScheduleBlockingSync));
|
|
|
|
std::thread([] {
|
|
HIP_CHECK_THREAD(hipSetDevice(0));
|
|
HIP_CHECK_THREAD(hipDeviceReset());
|
|
}).join();
|
|
HIP_CHECK_THREAD_FINALIZE();
|
|
|
|
unsigned int flags_after = 0u;
|
|
CHECK(hipGetDeviceFlags(&flags_after) == hipSuccess);
|
|
CHECK(flags_after == flags_before);
|
|
|
|
#if !defined(ENABLE_ADDRESS_SANITIZER)
|
|
CHECK(hipFree(ptr) == hipErrorInvalidValue);
|
|
#endif
|
|
|
|
if (cache_config_ret == hipSuccess) {
|
|
hipFuncCache_t cache_config;
|
|
CHECK(hipDeviceGetCacheConfig(&cache_config) == hipSuccess);
|
|
CHECK(cache_config == hipFuncCachePreferNone);
|
|
}
|
|
|
|
if (shared_mem_config_ret == hipSuccess) {
|
|
hipSharedMemConfig mem_config_after;
|
|
CHECK(hipDeviceGetSharedMemConfig(&mem_config_after) == hipSuccess);
|
|
CHECK(mem_config_after == mem_config_before);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* End doxygen group DeviceTest.
|
|
* @}
|
|
*/
|