Files
TheRock/rocm-libraries/projects/rocwmma/test/hip_device.hpp
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

130 lines
4.6 KiB
C++

/*******************************************************************************
*
* MIT License
*
* Copyright (C) 2021-2025 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef ROCWMMA_TEST_HIP_DEVICE_HPP
#define ROCWMMA_TEST_HIP_DEVICE_HPP
#include <hip/hip_runtime.h>
#include <hip/hip_runtime_api.h>
#if ROCWMMA_BENCHMARK_TESTS
#include <amd_smi/amdsmi.h>
#endif // ROCWMMA_BENCHMARK_TESTS
#include <rocwmma/internal/constants.hpp>
#include "performance.hpp"
#include "singleton.hpp"
namespace rocwmma
{
class HipDevice : public LazySingleton<HipDevice>
{
public:
// For static initialization
friend std::unique_ptr<HipDevice> std::make_unique<HipDevice>();
enum hipGcnArch_t : uint32_t
{
GFX908 = Constants::AMDGCN_ARCH_ID_GFX908,
GFX90A = Constants::AMDGCN_ARCH_ID_GFX90A,
GFX942 = Constants::AMDGCN_ARCH_ID_GFX942,
GFX950 = Constants::AMDGCN_ARCH_ID_GFX950,
GFX1100 = Constants::AMDGCN_ARCH_ID_GFX1100,
GFX1101 = Constants::AMDGCN_ARCH_ID_GFX1101,
GFX1102 = Constants::AMDGCN_ARCH_ID_GFX1102,
GFX1103 = Constants::AMDGCN_ARCH_ID_GFX1103,
GFX1150 = Constants::AMDGCN_ARCH_ID_GFX1150,
GFX1151 = Constants::AMDGCN_ARCH_ID_GFX1151,
GFX1152 = Constants::AMDGCN_ARCH_ID_GFX1152,
GFX1153 = Constants::AMDGCN_ARCH_ID_GFX1153,
GFX1200 = Constants::AMDGCN_ARCH_ID_GFX1200,
GFX1201 = Constants::AMDGCN_ARCH_ID_GFX1201,
GFX1250 = Constants::AMDGCN_ARCH_ID_GFX1250,
UNSUPPORTED_ARCH = Constants::AMDGCN_ARCH_ID_NONE,
};
enum hipWarpSize_t : uint32_t
{
Wave32 = Constants::AMDGCN_WAVE_SIZE_32,
Wave64 = Constants::AMDGCN_WAVE_SIZE_64,
UNSUPPORTED_WARP_SIZE = Constants::AMDGCN_WAVE_SIZE_NONE,
};
protected:
HipDevice();
public:
hipDevice_t getDeviceHandle() const;
hipDeviceProp_t getDeviceProps() const;
hipDeviceArch_t getDeviceArch() const;
hipGcnArch_t getGcnArch() const;
int warpSize() const;
int sharedMemSize() const;
int cuCount() const;
int maxFreqMhz() const;
int curFreqMhz() const;
template <typename InputT>
double peakGFlopsPerSec() const;
~HipDevice();
private:
hipDevice_t mHandle;
hipDeviceProp_t mProps;
hipDeviceArch_t mArch;
hipGcnArch_t mGcnArch;
int mWarpSize;
int mSharedMemSize;
int mCuCount;
int mMaxFreqMhz;
int mCurFreqMhz;
};
template <typename InputT>
double HipDevice::peakGFlopsPerSec() const
{
double result = -1.0;
switch(mGcnArch)
{
case hipGcnArch_t::GFX908:
result = calculatePeakGFlopsPerSec<InputT, ArchGfx908>(mCurFreqMhz, mCuCount);
break;
case hipGcnArch_t::GFX90A:
result = calculatePeakGFlopsPerSec<InputT, ArchGfx90a>(mCurFreqMhz, mCuCount);
break;
default:
result = calculatePeakGFlopsPerSec<InputT>(mCurFreqMhz, mCuCount);
}
return result;
}
} // namespace rocwmma
#endif // ROCWMMA_TEST_HIP_DEVICE_HPP