* Copyright (c) 2026 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/
#include <algorithm>
#include <cmath>
#include <vector>
#include "verify.h"
#include "blas_test.h"
#include "csv_loader.h"
#include "scalex_param.h"
#include "scalex_golden.h"
#include "scalex_npu_wrapper.h"
class ScalexArch35Test : public BlasTest<ScalexParam> { };
TEST_F(ScalexArch35Test, NullHandle) {
float alphaVal = 2.5f;
std::vector<float> xHost = makeBlasStrided(5, 1, "RANDOM", 42);
aclblasStatus_t ret = aclblasScalex_npu(
nullptr, 5,
&alphaVal, ACL_FLOAT,
xHost.data(), ACL_FLOAT,
1, ACL_FLOAT);
EXPECT_EQ(static_cast<int>(ret), static_cast<int>(ACLBLAS_STATUS_HANDLE_IS_NULLPTR));
}
TEST_F(ScalexArch35Test, AlphaNull) {
std::vector<float> xHost = makeBlasStrided(5, 1, "RANDOM", 42);
aclblasStatus_t ret = aclblasScalex_npu(
ScalexArch35Test::handle_, 5,
nullptr, ACL_FLOAT,
xHost.data(), ACL_FLOAT,
1, ACL_FLOAT);
EXPECT_EQ(static_cast<int>(ret), static_cast<int>(ACLBLAS_STATUS_INVALID_VALUE));
}
INSTANTIATE_TEST_SUITE_P(
Scalex, ScalexArch35Test,
::testing::ValuesIn(GetCasesFromCsv<ScalexParam>(ReplaceFileExtension2Csv(__FILE__))),
PrintCaseInfoString<ScalexParam>);
TEST_P(ScalexArch35Test, CsvDriven) {
const auto& p = GetParam();
std::vector<float> xHost;
if (p.x.method != BlasFillMode::M_NULLPTR) {
xHost = makeBlasStrided(p.n, p.incx, p.x, p.randomSeed);
}
float* xPtr = xHost.empty() ? nullptr : xHost.data();
float alphaLocal = p.alphaVal;
const void* alphaPtr = &alphaLocal;
std::vector<float> golden = xHost;
aclblasStatus_t ret = aclblasScalex_npu(
ScalexArch35Test::handle_, p.n,
alphaPtr, static_cast<aclDataType>(p.alphaType),
xPtr, static_cast<aclDataType>(p.xType),
p.incx, static_cast<aclDataType>(p.executionType),
p.alphaOnDevice);
EXPECT_EQ(static_cast<int>(ret), static_cast<int>(p.expectResult));
if (p.expectResult != ACLBLAS_STATUS_SUCCESS) return;
aclblasStatus_t cpuRet = aclblasScalex_cpu(
ScalexArch35Test::handle_, p.n,
alphaPtr, static_cast<aclDataType>(p.alphaType),
golden.data(), static_cast<aclDataType>(p.xType),
p.incx, static_cast<aclDataType>(p.executionType));
EXPECT_EQ(static_cast<int>(cpuRet), static_cast<int>(ACLBLAS_STATUS_SUCCESS));
VerifyConfig cfg;
cfg.mode = PrecisionMode::MERE_MARE;
switch (p.xType) {
case static_cast<int32_t>(ACL_FLOAT):
cfg.mereThreshold = std::pow(2.0f, -13);
cfg.mareMultiplier = 10.0;
break;
case static_cast<int32_t>(ACL_FLOAT16):
cfg.mereThreshold = std::pow(2.0f, -10);
cfg.mareMultiplier = 10.0;
break;
case static_cast<int32_t>(ACL_BF16):
cfg.mereThreshold = std::pow(2.0f, -7);
cfg.mareMultiplier = 10.0;
break;
default:
cfg.mereThreshold = std::pow(2.0f, -13);
cfg.mareMultiplier = 10.0;
break;
}
int absIncx = std::abs(p.incx);
EXPECT_TRUE(Verifier::verifyVector(
xPtr, golden.data(),
static_cast<size_t>(std::max(0, p.n)), absIncx,
cfg, p.caseName));
}