[INFO] Initializing environment for https://gitcode.com/pre-commit/pre-commit-hooks. [WARNING] repo `https://gitcode.com/pre-commit/pre-commit-hooks` uses deprecated stage names (commit, push) which will be removed in a future version. Hint: often `pre-commit autoupdate --repo https://gitcode.com/pre-commit/pre-commit-hooks` will fix this. if it does not -- consider reporting an issue to that repo. [INFO] Initializing environment for https://gitcode.com/pre-commit-clang/mirrors-clang-format. [INFO] Initializing environment for https://gitcode.com/gh_mirrors/ru/ruff-pre-commit. [INFO] Initializing environment for https://gitcode.com/gh_mirrors/co/codespell. [INFO] Installing environment for https://gitcode.com/pre-commit/pre-commit-hooks. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... [INFO] Installing environment for https://gitcode.com/pre-commit-clang/mirrors-clang-format. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... [INFO] Installing environment for https://gitcode.com/gh_mirrors/ru/ruff-pre-commit. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... [INFO] Installing environment for https://gitcode.com/gh_mirrors/co/codespell. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... trim trailing whitespace.................................................Passed fix end of files.........................................................Passed check yaml...........................................(no files to check)Skipped check for added large files..............................................Passed check for merge conflicts................................................Passed detect private key.......................................................Passed check json...........................................(no files to check)Skipped clang-format.............................................................Failed - hook id: clang-format - files were modified by this hook Formatting [1/1] reliability/matmul_abft_verify/examples/test_aclnn_matmul_abft_verify_bf16.cpp ruff check...........................................(no files to check)Skipped ruff format..........................................(no files to check)Skipped codespell................................................................Passed All changes made by hooks: diff --git a/reliability/matmul_abft_verify/examples/test_aclnn_matmul_abft_verify_bf16.cpp b/reliability/matmul_abft_verify/examples/test_aclnn_matmul_abft_verify_bf16.cpp index 8d41dd4..fb0be1d 100644 --- a/reliability/matmul_abft_verify/examples/test_aclnn_matmul_abft_verify_bf16.cpp +++ b/reliability/matmul_abft_verify/examples/test_aclnn_matmul_abft_verify_bf16.cpp @@ -26,8 +26,8 @@ } \ } while (0) -#define LOG_PRINT(message, ...) \ - do { \ +#define LOG_PRINT(message, ...) \ + do { \ std::printf(message, ##__VA_ARGS__); \ } while (0) @@ -36,8 +36,7 @@ using Bf16 = uint16_t; Bf16 FloatToBf16(float value) { uint32_t bits = 0; - std::copy_n(reinterpret_cast(&value), sizeof(value), - reinterpret_cast(&bits)); + std::copy_n(reinterpret_cast(&value), sizeof(value), reinterpret_cast(&bits)); bits += 0x7FFFU + ((bits >> 16U) & 1U); return static_cast(bits >> 16U); } @@ -46,8 +45,7 @@ float Bf16ToFloat(Bf16 value) { uint32_t bits = static_cast(value) << 16U; float result = 0.0F; - std::copy_n(reinterpret_cast(&bits), sizeof(bits), - reinterpret_cast(&result)); + std::copy_n(reinterpret_cast(&bits), sizeof(bits), reinterpret_cast(&result)); return result; } @@ -61,8 +59,7 @@ struct TestArgs { void Print() const { - LOG_PRINT("Args: m=%ld n=%ld k=%ld eMax=%f verbose=%d deviceId=%d\n", - m, n, k, eMax, verbose, deviceId); + LOG_PRINT("Args: m=%ld n=%ld k=%ld eMax=%f verbose=%d deviceId=%d\n", m, n, k, eMax, verbose, deviceId); } }; @@ -76,8 +73,9 @@ int64_t GetShapeSize(const std::vector& shape) } template -int CreateAclTensor(const std::vector& hostData, const std::vector& shape, - void** deviceAddr, aclDataType dataType, aclTensor** tensor) +int CreateAclTensor( + const std::vector& hostData, const std::vector& shape, void** deviceAddr, aclDataType dataType, + aclTensor** tensor) { auto size = GetShapeSize(shape) * static_cast(sizeof(T)); auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); @@ -89,9 +87,9 @@ int CreateAclTensor(const std::vector& hostData, const std::vector& for (int64_t i = static_cast(shape.size()) - 2; i >= 0; --i) { strides[i] = shape[i + 1] * strides[i + 1]; } - *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, - strides.data(), 0, ACL_FORMAT_ND, - shape.data(), shape.size(), *deviceAddr); + *tensor = aclCreateTensor( + shape.data(), shape.size(), dataType, strides.data(), 0, ACL_FORMAT_ND, shape.data(), shape.size(), + *deviceAddr); CHECK_RET(*tensor != nullptr, LOG_PRINT("aclCreateTensor failed.\n"); return ACL_ERROR_FAILURE); return ACL_SUCCESS; } @@ -100,15 +98,11 @@ template int CopyDeviceToHost(std::vector& hostData, const void* deviceAddr, const char* name) { const size_t bytes = hostData.size() * sizeof(T); - const auto ret = aclrtMemcpy(hostData.data(), bytes, deviceAddr, bytes, - ACL_MEMCPY_DEVICE_TO_HOST); - CHECK_RET(ret == ACL_SUCCESS, - LOG_PRINT("copy %s from device to host failed. ERROR: %d\n", name, ret); - return ret); + const auto ret = aclrtMemcpy(hostData.data(), bytes, deviceAddr, bytes, ACL_MEMCPY_DEVICE_TO_HOST); + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy %s from device to host failed. ERROR: %d\n", name, ret); return ret); return ACL_SUCCESS; } - int InitAcl(int32_t deviceId, aclrtContext* context, aclrtStream* stream) { auto ret = aclInit(nullptr); @@ -197,8 +191,7 @@ struct ExampleShapes { ExampleShapes CreateExampleShapes(const TestArgs& args) { const int64_t splitN = (args.n + 255) / 256; - return {{args.m, args.k}, {args.k, args.n}, {args.n}, {args.m, args.n}, - {((args.m + 7) / 8) * splitN}}; + return {{args.m, args.k}, {args.k, args.n}, {args.n}, {args.m, args.n}, {((args.m + 7) / 8) * splitN}}; } struct ExampleData { @@ -251,19 +244,38 @@ int CreateExampleTensors(const ExampleData& data, const ExampleShapes& shapes, E void DestroyExampleTensors(ExampleTensors* tensors) { - auto destroy = [](aclTensor*& tensor) { if (tensor) { aclDestroyTensor(tensor); tensor = nullptr; } }; - auto free = [](void*& address) { if (address) { aclrtFree(address); address = nullptr; } }; - destroy(tensors->a); destroy(tensors->b); destroy(tensors->xv); destroy(tensors->c); destroy(tensors->compRow); - free(tensors->devA); free(tensors->devB); free(tensors->devXv); free(tensors->devC); free(tensors->devCompRow); + auto destroy = [](aclTensor*& tensor) { + if (tensor) { + aclDestroyTensor(tensor); + tensor = nullptr; + } + }; + auto free = [](void*& address) { + if (address) { + aclrtFree(address); + address = nullptr; + } + }; + destroy(tensors->a); + destroy(tensors->b); + destroy(tensors->xv); + destroy(tensors->c); + destroy(tensors->compRow); + free(tensors->devA); + free(tensors->devB); + free(tensors->devXv); + free(tensors->devC); + free(tensors->devCompRow); } int ExecuteMatmulAbftVerify(const TestArgs& args, const ExampleTensors& tensors, aclrtStream stream) { uint64_t workspaceSize = 0; aclOpExecutor* executor = nullptr; - auto ret = aclnnMatmulAbftVerifyGetWorkspaceSize(tensors.a, tensors.b, tensors.c, tensors.xv, args.eMax, - tensors.compRow, &workspaceSize, &executor); - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnMatmulAbftVerifyGetWorkspaceSize failed. ERROR: %d\n", ret); return ret); + auto ret = aclnnMatmulAbftVerifyGetWorkspaceSize( + tensors.a, tensors.b, tensors.c, tensors.xv, args.eMax, tensors.compRow, &workspaceSize, &executor); + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnMatmulAbftVerifyGetWorkspaceSize failed. ERROR: %d\n", ret); + return ret); void* workspaceAddr = nullptr; if (workspaceSize > 0) { ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);