Files
TheRock/rocm-libraries/projects/hiptensor/test/00_unit/util_test.cpp
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

146 lines
7.4 KiB
C++

/*******************************************************************************
*
* MIT License
*
* Copyright (C) 2023-2026 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.
*
*******************************************************************************/
#include <gtest/gtest.h>
#include <iostream>
#include <data_types.hpp>
#include <data_types_impl.hpp>
#include <hip/hip_runtime.h>
#include <hiptensor/hiptensor.h>
#include <logger.hpp>
#include <util.hpp>
TEST(stridesFromLengthsTest, UtilTest)
{
std::vector<int> input = {3, 4, 5};
std::vector<int> expected = {20, 5, 1};
auto output = hiptensor::stridesFromLengths(input, false); // col_major == false
EXPECT_EQ(output, expected);
expected = {1, 3, 12};
output = hiptensor::stridesFromLengths(input, true); // col_major == true
EXPECT_EQ(output, expected);
input = {};
expected = {};
output = hiptensor::stridesFromLengths(input);
EXPECT_EQ(output, expected);
}
TEST(CheckApiParamsTest, UtilTest)
{
using hiptensor::Logger;
auto& logger = Logger::instance();
hiptensorStatus_t checkResult = HIPTENSOR_STATUS_SUCCESS;
CheckApiParams(checkResult, *logger, HIPTENSOR_STATUS_NOT_INITIALIZED, nullptr);
EXPECT_EQ(checkResult, HIPTENSOR_STATUS_NOT_INITIALIZED);
}
TEST(hiptensorGetVersionTest, UtilTest)
{
EXPECT_EQ(hiptensorGetVersion(), 2004000);
}
TEST(logLevelToStringTest, UtilTest)
{
EXPECT_STREQ(hiptensor::logLevelToString(HIPTENSOR_LOG_LEVEL_OFF).c_str(),
"HIPTENSOR_LOG_LEVEL_OFF");
EXPECT_STREQ(hiptensor::logLevelToString(HIPTENSOR_LOG_LEVEL_ERROR).c_str(),
"HIPTENSOR_LOG_LEVEL_ERROR");
EXPECT_STREQ(hiptensor::logLevelToString(HIPTENSOR_LOG_LEVEL_PERF_TRACE).c_str(),
"HIPTENSOR_LOG_LEVEL_PERF_TRACE");
EXPECT_STREQ(hiptensor::logLevelToString(HIPTENSOR_LOG_LEVEL_PERF_HINT).c_str(),
"HIPTENSOR_LOG_LEVEL_PERF_HINT");
EXPECT_STREQ(hiptensor::logLevelToString(HIPTENSOR_LOG_LEVEL_HEURISTICS_TRACE).c_str(),
"HIPTENSOR_LOG_LEVEL_HEURISTICS_TRACE");
EXPECT_STREQ(hiptensor::logLevelToString(HIPTENSOR_LOG_LEVEL_API_TRACE).c_str(),
"HIPTENSOR_LOG_LEVEL_API_TRACE");
}
TEST(opTypeToStringTest, UtilTest)
{
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_IDENTITY).c_str(), "HIPTENSOR_OP_IDENTITY");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_SQRT).c_str(), "HIPTENSOR_OP_SQRT");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_RELU).c_str(), "HIPTENSOR_OP_RELU");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_CONJ).c_str(), "HIPTENSOR_OP_CONJ");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_RCP).c_str(), "HIPTENSOR_OP_RCP");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_SIGMOID).c_str(), "HIPTENSOR_OP_SIGMOID");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_TANH).c_str(), "HIPTENSOR_OP_TANH");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_EXP).c_str(), "HIPTENSOR_OP_EXP");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_LOG).c_str(), "HIPTENSOR_OP_LOG");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_ABS).c_str(), "HIPTENSOR_OP_ABS");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_NEG).c_str(), "HIPTENSOR_OP_NEG");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_SIN).c_str(), "HIPTENSOR_OP_SIN");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_COS).c_str(), "HIPTENSOR_OP_COS");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_TAN).c_str(), "HIPTENSOR_OP_TAN");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_SINH).c_str(), "HIPTENSOR_OP_SINH");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_COSH).c_str(), "HIPTENSOR_OP_COSH");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_ASIN).c_str(), "HIPTENSOR_OP_ASIN");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_ACOS).c_str(), "HIPTENSOR_OP_ACOS");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_ATAN).c_str(), "HIPTENSOR_OP_ATAN");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_ASINH).c_str(), "HIPTENSOR_OP_ASINH");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_ACOSH).c_str(), "HIPTENSOR_OP_ACOSH");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_ATANH).c_str(), "HIPTENSOR_OP_ATANH");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_CEIL).c_str(), "HIPTENSOR_OP_CEIL");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_FLOOR).c_str(), "HIPTENSOR_OP_FLOOR");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_ADD).c_str(), "HIPTENSOR_OP_ADD");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_MUL).c_str(), "HIPTENSOR_OP_MUL");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_MAX).c_str(), "HIPTENSOR_OP_MAX");
EXPECT_STREQ(hiptensor::opTypeToString(HIPTENSOR_OP_MIN).c_str(), "HIPTENSOR_OP_MIN");
}
TEST(convertToHipTensorDataTypeTypeToStringTest, UtilTest)
{
EXPECT_EQ(hiptensor::convertToHipTensorDataType(HIPTENSOR_COMPUTE_DESC_16BF), HIPTENSOR_R_16BF);
EXPECT_EQ(hiptensor::convertToHipTensorDataType(HIPTENSOR_COMPUTE_DESC_16F), HIPTENSOR_R_16F);
EXPECT_EQ(hiptensor::convertToHipTensorDataType(HIPTENSOR_COMPUTE_DESC_32F), HIPTENSOR_R_32F);
EXPECT_EQ(hiptensor::convertToHipTensorDataType(HIPTENSOR_COMPUTE_DESC_64F), HIPTENSOR_R_64F);
EXPECT_EQ(hiptensor::convertToHipTensorDataType(HIPTENSOR_COMPUTE_DESC_C32F), HIPTENSOR_C_32F);
EXPECT_EQ(hiptensor::convertToHipTensorDataType(HIPTENSOR_COMPUTE_DESC_C64F), HIPTENSOR_C_64F);
}
TEST(algoTypeToStringTest, UtilTest)
{
EXPECT_STREQ(hiptensor::algoTypeToString(HIPTENSOR_ALGO_ACTOR_CRITIC).c_str(),
"HIPTENSOR_ALGO_ACTOR_CRITIC");
EXPECT_STREQ(hiptensor::algoTypeToString(HIPTENSOR_ALGO_DEFAULT).c_str(),
"HIPTENSOR_ALGO_DEFAULT");
EXPECT_STREQ(hiptensor::algoTypeToString(HIPTENSOR_ALGO_DEFAULT_PATIENT).c_str(),
"HIPTENSOR_ALGO_DEFAULT_PATIENT");
}
TEST(workSizePrefToStringTest, UtilTest)
{
EXPECT_STREQ(hiptensor::workSizePrefToString(HIPTENSOR_WORKSPACE_MIN).c_str(),
"HIPTENSOR_WORKSPACE_MIN");
EXPECT_STREQ(hiptensor::workSizePrefToString(HIPTENSOR_WORKSPACE_DEFAULT).c_str(),
"HIPTENSOR_WORKSPACE_DEFAULT");
EXPECT_STREQ(hiptensor::workSizePrefToString(HIPTENSOR_WORKSPACE_MAX).c_str(),
"HIPTENSOR_WORKSPACE_MAX");
}