Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refuce f16 #261

Merged
merged 19 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions library/src/reduction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,48 @@ set(HIPTENSOR_REDUCTION_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/reduction_cpu_reference.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_cpu_reference_instances.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_1_1_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_2_1_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_2_2_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_3_1_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_3_2_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_3_3_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_4_1_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_4_2_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_4_3_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_4_4_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_5_1_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_5_2_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_5_3_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_5_4_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_5_5_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_6_1_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_6_2_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_6_3_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_6_4_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_6_5_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_6_6_f16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_1_1_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_2_1_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_2_2_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_3_1_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_3_2_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_3_3_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_4_1_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_4_2_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_4_3_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_4_4_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_5_1_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_5_2_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_5_3_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_5_4_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_5_5_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_6_1_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_6_2_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_6_3_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_6_4_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_6_5_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_6_6_bf16_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_1_1_f32_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_2_1_f32_f32_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reduction_solution_2_2_f32_f32_instance.cpp
Expand Down
9 changes: 8 additions & 1 deletion library/src/reduction/hiptensor_reduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,16 @@ hiptensorStatus_t hiptensorReduction(const hiptensorHandle_t* handle,
auto ADataType = descA->mType;
auto DDataType = descD->mType;

auto internalTypeCompute = typeCompute;
if(typeCompute == HIPTENSOR_COMPUTE_16F || typeCompute == HIPTENSOR_COMPUTE_16BF)
{
// CK does not support f16 or bf16 as compute type
internalTypeCompute = HIPTENSOR_COMPUTE_32F;
}

// Query reduction solutions for the correct reduction operation and type
auto solutionQ = instances->querySolutions(ADataType,
typeCompute,
internalTypeCompute,
DDataType,
rankA,
numReduceDim,
Expand Down
13 changes: 10 additions & 3 deletions library/src/reduction/reduction_cpu_reference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,22 @@ hiptensorStatus_t hiptensorReductionReference(const void*
auto ADataType = descA->mType;
auto DDataType = descD->mType;

auto internalTypeCompute = typeCompute;
if(typeCompute == HIPTENSOR_COMPUTE_16F || typeCompute == HIPTENSOR_COMPUTE_16BF)
{
// CK does not support f16 or bf16 as compute type
internalTypeCompute = HIPTENSOR_COMPUTE_32F;
}

auto& instances = hiptensor::ReductionCpuReferenceInstances::instance();
auto solutionQ = instances->querySolutions(ADataType,
typeCompute,
internalTypeCompute,
DDataType,
rankA,
numReduceDim,
opReduce,
true, // @TODO hardcode
false); // @TODO hardcode
true, // propagateNan
false); // outputIndex

double alphaD;
if(alpha != nullptr)
Expand Down
235 changes: 161 additions & 74 deletions library/src/reduction/reduction_cpu_reference_instances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,38 @@
#include "reduction_cpu_reference_impl.hpp"
#include <hiptensor/internal/types.hpp>

#define REG_CPU_SOLUTION(dim_count, reduced_dim_count, type) \
registerSolutions(enumerateReferenceSolutions<type, \
type, \
type, \
dim_count, \
reduced_dim_count, \
HIPTENSOR_OP_ADD, \
true, \
false>()); \
registerSolutions(enumerateReferenceSolutions<type, \
type, \
type, \
dim_count, \
reduced_dim_count, \
HIPTENSOR_OP_MUL, \
true, \
false>()); \
registerSolutions(enumerateReferenceSolutions<type, \
type, \
type, \
dim_count, \
reduced_dim_count, \
HIPTENSOR_OP_MIN, \
true, \
false>()); \
registerSolutions(enumerateReferenceSolutions<type, \
type, \
type, \
dim_count, \
reduced_dim_count, \
HIPTENSOR_OP_MAX, \
true, \
#define REG_CPU_SOLUTION(dim_count, reduced_dim_count, type, computeType) \
cgmillette marked this conversation as resolved.
Show resolved Hide resolved
registerSolutions(enumerateReferenceSolutions<type, \
computeType, \
type, \
dim_count, \
reduced_dim_count, \
HIPTENSOR_OP_ADD, \
true, \
false>()); \
registerSolutions(enumerateReferenceSolutions<type, \
computeType, \
type, \
dim_count, \
reduced_dim_count, \
HIPTENSOR_OP_MUL, \
true, \
false>()); \
registerSolutions(enumerateReferenceSolutions<type, \
computeType, \
type, \
dim_count, \
reduced_dim_count, \
HIPTENSOR_OP_MIN, \
true, \
false>()); \
registerSolutions(enumerateReferenceSolutions<type, \
computeType, \
type, \
dim_count, \
reduced_dim_count, \
HIPTENSOR_OP_MAX, \
true, \
false>());

namespace hiptensor
Expand All @@ -83,49 +83,136 @@ namespace hiptensor
// HIPTENSOR_OP_ADD,
// true, // PropagateNan,
// false>()); // OutputIndex,
REG_CPU_SOLUTION(1, 1, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(2, 1, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(2, 2, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(3, 1, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(3, 2, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(3, 3, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(4, 1, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(4, 2, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(4, 3, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(4, 4, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(5, 1, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(5, 2, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(5, 3, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(5, 4, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(5, 5, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(6, 1, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(6, 2, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(6, 3, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(6, 4, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(6, 5, ck::half_t, ck::half_t);
REG_CPU_SOLUTION(6, 6, ck::half_t, ck::half_t);

REG_CPU_SOLUTION(1, 1, hiptensor::float32_t);
REG_CPU_SOLUTION(2, 1, hiptensor::float32_t);
REG_CPU_SOLUTION(2, 2, hiptensor::float32_t);
REG_CPU_SOLUTION(3, 1, hiptensor::float32_t);
REG_CPU_SOLUTION(3, 2, hiptensor::float32_t);
REG_CPU_SOLUTION(3, 3, hiptensor::float32_t);
REG_CPU_SOLUTION(4, 1, hiptensor::float32_t);
REG_CPU_SOLUTION(4, 2, hiptensor::float32_t);
REG_CPU_SOLUTION(4, 3, hiptensor::float32_t);
REG_CPU_SOLUTION(4, 4, hiptensor::float32_t);
REG_CPU_SOLUTION(5, 1, hiptensor::float32_t);
REG_CPU_SOLUTION(5, 2, hiptensor::float32_t);
REG_CPU_SOLUTION(5, 3, hiptensor::float32_t);
REG_CPU_SOLUTION(5, 4, hiptensor::float32_t);
REG_CPU_SOLUTION(5, 5, hiptensor::float32_t);
REG_CPU_SOLUTION(6, 1, hiptensor::float32_t);
REG_CPU_SOLUTION(6, 2, hiptensor::float32_t);
REG_CPU_SOLUTION(6, 3, hiptensor::float32_t);
REG_CPU_SOLUTION(6, 4, hiptensor::float32_t);
REG_CPU_SOLUTION(6, 5, hiptensor::float32_t);
REG_CPU_SOLUTION(6, 6, hiptensor::float32_t);
REG_CPU_SOLUTION(1, 1, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(2, 1, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(2, 2, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(3, 1, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(3, 2, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(3, 3, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(4, 1, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(4, 2, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(4, 3, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(4, 4, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(5, 1, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(5, 2, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(5, 3, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(5, 4, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(5, 5, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(6, 1, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(6, 2, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(6, 3, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(6, 4, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(6, 5, ck::bhalf_t, ck::bhalf_t);
REG_CPU_SOLUTION(6, 6, ck::bhalf_t, ck::bhalf_t);

REG_CPU_SOLUTION(1, 1, hiptensor::float64_t);
REG_CPU_SOLUTION(2, 1, hiptensor::float64_t);
REG_CPU_SOLUTION(2, 2, hiptensor::float64_t);
REG_CPU_SOLUTION(3, 1, hiptensor::float64_t);
REG_CPU_SOLUTION(3, 2, hiptensor::float64_t);
REG_CPU_SOLUTION(3, 3, hiptensor::float64_t);
REG_CPU_SOLUTION(4, 1, hiptensor::float64_t);
REG_CPU_SOLUTION(4, 2, hiptensor::float64_t);
REG_CPU_SOLUTION(4, 3, hiptensor::float64_t);
REG_CPU_SOLUTION(4, 4, hiptensor::float64_t);
REG_CPU_SOLUTION(5, 1, hiptensor::float64_t);
REG_CPU_SOLUTION(5, 2, hiptensor::float64_t);
REG_CPU_SOLUTION(5, 3, hiptensor::float64_t);
REG_CPU_SOLUTION(5, 4, hiptensor::float64_t);
REG_CPU_SOLUTION(5, 5, hiptensor::float64_t);
REG_CPU_SOLUTION(6, 1, hiptensor::float64_t);
REG_CPU_SOLUTION(6, 2, hiptensor::float64_t);
REG_CPU_SOLUTION(6, 3, hiptensor::float64_t);
REG_CPU_SOLUTION(6, 4, hiptensor::float64_t);
REG_CPU_SOLUTION(6, 5, hiptensor::float64_t);
REG_CPU_SOLUTION(6, 6, hiptensor::float64_t);
REG_CPU_SOLUTION(1, 1, ck::half_t, float);
REG_CPU_SOLUTION(2, 1, ck::half_t, float);
REG_CPU_SOLUTION(2, 2, ck::half_t, float);
REG_CPU_SOLUTION(3, 1, ck::half_t, float);
REG_CPU_SOLUTION(3, 2, ck::half_t, float);
REG_CPU_SOLUTION(3, 3, ck::half_t, float);
REG_CPU_SOLUTION(4, 1, ck::half_t, float);
REG_CPU_SOLUTION(4, 2, ck::half_t, float);
REG_CPU_SOLUTION(4, 3, ck::half_t, float);
REG_CPU_SOLUTION(4, 4, ck::half_t, float);
REG_CPU_SOLUTION(5, 1, ck::half_t, float);
REG_CPU_SOLUTION(5, 2, ck::half_t, float);
REG_CPU_SOLUTION(5, 3, ck::half_t, float);
REG_CPU_SOLUTION(5, 4, ck::half_t, float);
REG_CPU_SOLUTION(5, 5, ck::half_t, float);
REG_CPU_SOLUTION(6, 1, ck::half_t, float);
REG_CPU_SOLUTION(6, 2, ck::half_t, float);
REG_CPU_SOLUTION(6, 3, ck::half_t, float);
REG_CPU_SOLUTION(6, 4, ck::half_t, float);
REG_CPU_SOLUTION(6, 5, ck::half_t, float);
REG_CPU_SOLUTION(6, 6, ck::half_t, float);

REG_CPU_SOLUTION(1, 1, ck::bhalf_t, float);
REG_CPU_SOLUTION(2, 1, ck::bhalf_t, float);
REG_CPU_SOLUTION(2, 2, ck::bhalf_t, float);
REG_CPU_SOLUTION(3, 1, ck::bhalf_t, float);
REG_CPU_SOLUTION(3, 2, ck::bhalf_t, float);
REG_CPU_SOLUTION(3, 3, ck::bhalf_t, float);
REG_CPU_SOLUTION(4, 1, ck::bhalf_t, float);
REG_CPU_SOLUTION(4, 2, ck::bhalf_t, float);
REG_CPU_SOLUTION(4, 3, ck::bhalf_t, float);
REG_CPU_SOLUTION(4, 4, ck::bhalf_t, float);
REG_CPU_SOLUTION(5, 1, ck::bhalf_t, float);
REG_CPU_SOLUTION(5, 2, ck::bhalf_t, float);
REG_CPU_SOLUTION(5, 3, ck::bhalf_t, float);
REG_CPU_SOLUTION(5, 4, ck::bhalf_t, float);
REG_CPU_SOLUTION(5, 5, ck::bhalf_t, float);
REG_CPU_SOLUTION(6, 1, ck::bhalf_t, float);
REG_CPU_SOLUTION(6, 2, ck::bhalf_t, float);
REG_CPU_SOLUTION(6, 3, ck::bhalf_t, float);
REG_CPU_SOLUTION(6, 4, ck::bhalf_t, float);
REG_CPU_SOLUTION(6, 5, ck::bhalf_t, float);
REG_CPU_SOLUTION(6, 6, ck::bhalf_t, float);

REG_CPU_SOLUTION(1, 1, float, float);
REG_CPU_SOLUTION(2, 1, float, float);
REG_CPU_SOLUTION(2, 2, float, float);
REG_CPU_SOLUTION(3, 1, float, float);
REG_CPU_SOLUTION(3, 2, float, float);
REG_CPU_SOLUTION(3, 3, float, float);
REG_CPU_SOLUTION(4, 1, float, float);
REG_CPU_SOLUTION(4, 2, float, float);
REG_CPU_SOLUTION(4, 3, float, float);
REG_CPU_SOLUTION(4, 4, float, float);
REG_CPU_SOLUTION(5, 1, float, float);
REG_CPU_SOLUTION(5, 2, float, float);
REG_CPU_SOLUTION(5, 3, float, float);
REG_CPU_SOLUTION(5, 4, float, float);
REG_CPU_SOLUTION(5, 5, float, float);
REG_CPU_SOLUTION(6, 1, float, float);
REG_CPU_SOLUTION(6, 2, float, float);
REG_CPU_SOLUTION(6, 3, float, float);
REG_CPU_SOLUTION(6, 4, float, float);
REG_CPU_SOLUTION(6, 5, float, float);
REG_CPU_SOLUTION(6, 6, float, float);

REG_CPU_SOLUTION(1, 1, double, double);
REG_CPU_SOLUTION(2, 1, double, double);
REG_CPU_SOLUTION(2, 2, double, double);
REG_CPU_SOLUTION(3, 1, double, double);
REG_CPU_SOLUTION(3, 2, double, double);
REG_CPU_SOLUTION(3, 3, double, double);
REG_CPU_SOLUTION(4, 1, double, double);
REG_CPU_SOLUTION(4, 2, double, double);
REG_CPU_SOLUTION(4, 3, double, double);
REG_CPU_SOLUTION(4, 4, double, double);
REG_CPU_SOLUTION(5, 1, double, double);
REG_CPU_SOLUTION(5, 2, double, double);
REG_CPU_SOLUTION(5, 3, double, double);
REG_CPU_SOLUTION(5, 4, double, double);
REG_CPU_SOLUTION(5, 5, double, double);
REG_CPU_SOLUTION(6, 1, double, double);
REG_CPU_SOLUTION(6, 2, double, double);
REG_CPU_SOLUTION(6, 3, double, double);
REG_CPU_SOLUTION(6, 4, double, double);
REG_CPU_SOLUTION(6, 5, double, double);
REG_CPU_SOLUTION(6, 6, double, double);
}
} // namespace hiptensor
Loading
Loading