mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-05-20 12:59:49 +00:00
Enable bf16 RNE on gfx950 (#2542)
* Enable bf16 RNE for gfx950
* test bhalf
* fix
* fix
* Comments fixes
* fixes
* clean
* fix
[ROCm/composable_kernel commit: 685771b875]
This commit is contained in:
@@ -2,8 +2,12 @@
|
||||
// Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
|
||||
#include "ck/utility/data_type.hpp"
|
||||
#include "ck/utility/type_convert.hpp"
|
||||
#include "ck/host_utility/hip_check_error.hpp"
|
||||
|
||||
using ck::bhalf_t;
|
||||
using ck::type_convert;
|
||||
@@ -46,3 +50,45 @@ TEST(BHALF_T, MantisaExpOverflow)
|
||||
ASSERT_TRUE(std::isnan(float_val));
|
||||
ASSERT_TRUE(std::isnan(type_convert<float>(type_convert<bhalf_t>(float_val))));
|
||||
}
|
||||
|
||||
__global__ void cast(const float input, float* output)
|
||||
{
|
||||
const bhalf_t bhalf_val = type_convert<bhalf_t>(input);
|
||||
*output = type_convert<float>(bhalf_val);
|
||||
}
|
||||
|
||||
TEST(BHALF_T, CastOnDevice)
|
||||
{
|
||||
constexpr int num_vals = 11;
|
||||
const float abs_tol = std::pow(2, -7);
|
||||
float float_vals[num_vals] = {0.5, 0.875, 1.5, 1, 2, 4, 8, 16, 32, 64, 128};
|
||||
|
||||
float* float_val_after_cast_dev;
|
||||
float float_val_after_cast_host;
|
||||
hip_check_error(hipMalloc(&float_val_after_cast_dev, sizeof(float)));
|
||||
|
||||
// Positive
|
||||
for(int idx = 0; idx < num_vals; idx++)
|
||||
{
|
||||
cast<<<1, 1>>>(float_vals[idx], float_val_after_cast_dev);
|
||||
|
||||
hip_check_error(hipMemcpy(&float_val_after_cast_host,
|
||||
float_val_after_cast_dev,
|
||||
sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
|
||||
ASSERT_NEAR(float_val_after_cast_host, float_vals[idx], abs_tol);
|
||||
}
|
||||
// Negative
|
||||
for(int idx = 0; idx < num_vals; idx++)
|
||||
{
|
||||
cast<<<1, 1>>>(-float_vals[idx], float_val_after_cast_dev);
|
||||
|
||||
hip_check_error(hipMemcpy(&float_val_after_cast_host,
|
||||
float_val_after_cast_dev,
|
||||
sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
|
||||
ASSERT_NEAR(float_val_after_cast_host, -float_vals[idx], abs_tol);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user