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
116 lines
3.6 KiB
C++
116 lines
3.6 KiB
C++
// Copyright © Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// GPU reference validator kernels - compiled at runtime via HipRTC.
|
|
// DATA_TYPE must be defined at compile time via -DDATA_TYPE=<type>.
|
|
// COMPUTE_TYPE must be defined for accumulation precision.
|
|
//
|
|
// Both reference and implementation tensors share the same element type.
|
|
// Kernels set a single atomic failureFlag (0 = all passed, 1 = any failed).
|
|
|
|
#include "GpuRefTypes.h"
|
|
#include "GpuRefValidatorArgs.h"
|
|
|
|
using namespace gpu_ref;
|
|
|
|
// Decompose a linear element index into strided offsets for two tensors.
|
|
// Computes multi-dimensional coordinates from linearIdx using dims (innermost-last),
|
|
// then dot-products with each tensor's strides to get physical offsets.
|
|
__device__ inline void decomposeAndComputeOffsets(long long linearIdx,
|
|
const long long* dims,
|
|
const long long* refStrides,
|
|
const long long* implStrides,
|
|
int ndim,
|
|
long long& refOffset,
|
|
long long& implOffset)
|
|
{
|
|
refOffset = 0;
|
|
implOffset = 0;
|
|
for(int d = ndim - 1; d >= 0; --d)
|
|
{
|
|
long long coord = linearIdx % dims[d];
|
|
linearIdx /= dims[d];
|
|
refOffset += coord * refStrides[d];
|
|
implOffset += coord * implStrides[d];
|
|
}
|
|
}
|
|
|
|
// Floating-point allClose validation kernel.
|
|
// For each element i: passes if |impl[i] - ref[i]| <= atol + rtol * |ref[i]|
|
|
// Fails on NaN or Inf in either tensor.
|
|
// Sets failureFlag to 1 atomically if any element fails.
|
|
extern "C" __global__ void validateAllClose(ValidatorArgs args)
|
|
{
|
|
auto idx = static_cast<long long>(blockIdx.x) * blockDim.x + threadIdx.x;
|
|
if(idx >= args.totalElements)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if(*args.failureFlag != 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
const auto* ref = static_cast<const DATA_TYPE*>(args.reference);
|
|
const auto* impl = static_cast<const DATA_TYPE*>(args.implementation);
|
|
|
|
long long refIdx = idx;
|
|
long long implIdx = idx;
|
|
if(args.ndim > 0)
|
|
{
|
|
decomposeAndComputeOffsets(
|
|
idx, args.dims, args.refStrides, args.implStrides, args.ndim, refIdx, implIdx);
|
|
}
|
|
|
|
auto refVal = toAccum(ref[refIdx]);
|
|
auto implVal = toAccum(impl[implIdx]);
|
|
|
|
if(isnan(refVal) || isnan(implVal) || isinf(refVal) || isinf(implVal))
|
|
{
|
|
atomicMax(args.failureFlag, 1);
|
|
return;
|
|
}
|
|
|
|
auto absDiff = fabs(implVal - refVal);
|
|
auto threshold = static_cast<COMPUTE_TYPE>(args.absoluteTolerance)
|
|
+ static_cast<COMPUTE_TYPE>(args.relativeTolerance) * fabs(refVal);
|
|
|
|
if(absDiff > threshold)
|
|
{
|
|
atomicMax(args.failureFlag, 1);
|
|
}
|
|
}
|
|
|
|
// Integer exact-equality validation kernel.
|
|
// Sets failureFlag to 1 atomically if any element differs.
|
|
extern "C" __global__ void validateExact(ValidatorArgs args)
|
|
{
|
|
auto idx = static_cast<long long>(blockIdx.x) * blockDim.x + threadIdx.x;
|
|
if(idx >= args.totalElements)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if(*args.failureFlag != 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
const auto* ref = static_cast<const DATA_TYPE*>(args.reference);
|
|
const auto* impl = static_cast<const DATA_TYPE*>(args.implementation);
|
|
|
|
long long refIdx = idx;
|
|
long long implIdx = idx;
|
|
if(args.ndim > 0)
|
|
{
|
|
decomposeAndComputeOffsets(
|
|
idx, args.dims, args.refStrides, args.implStrides, args.ndim, refIdx, implIdx);
|
|
}
|
|
|
|
if(ref[refIdx] != impl[implIdx])
|
|
{
|
|
atomicMax(args.failureFlag, 1);
|
|
}
|
|
}
|