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 12 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
22 changes: 13 additions & 9 deletions library/src/hiptensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,17 @@ hiptensorStatus_t hiptensorInitTensorDescriptor(const hiptensorHandle_t* han
return HIPTENSOR_STATUS_NOT_INITIALIZED;
}

if((lens == nullptr)
if((lens == nullptr && strides != nullptr)
CongMa13 marked this conversation as resolved.
Show resolved Hide resolved
|| ((dataType != HIP_R_16F) && (dataType != HIP_R_16BF) && (dataType != HIP_R_32F)
&& (dataType != HIP_R_64F) && (dataType != HIP_C_32F)
&& (dataType != HIP_C_64F))
&& (dataType != HIP_R_64F) && (dataType != HIP_C_32F) && (dataType != HIP_C_64F))
|| ((unaryOp != HIPTENSOR_OP_IDENTITY) && (unaryOp != HIPTENSOR_OP_SQRT)))
{
auto errorCode = HIPTENSOR_STATUS_INVALID_VALUE;
if(lens == nullptr)
if(lens == nullptr && strides != nullptr)
CongMa13 marked this conversation as resolved.
Show resolved Hide resolved
{
snprintf(msg,
sizeof(msg),
"Tensor Initialization Error : lens = nullptr (%s)",
"Tensor Initialization Error : lens = nullptr and strides != nullptr (%s)",
hiptensorGetErrorString(errorCode));
}
else if((unaryOp != HIPTENSOR_OP_IDENTITY) && (unaryOp != HIPTENSOR_OP_SQRT))
Expand Down Expand Up @@ -200,10 +199,15 @@ hiptensorStatus_t hiptensorInitTensorDescriptor(const hiptensorHandle_t* han
else
{
// Re-construct strides from lengths, assuming packed.
std::vector<std::size_t> l(lens, lens + numModes);
std::vector<std::size_t> s = hiptensor::stridesFromLengths(l);

*desc = {dataType, l, s, unaryOp};
if(lens != nullptr)
{
auto lensVector = std::vector<std::size_t>(lens, lens + numModes);
*desc = {dataType, lensVector, hiptensor::stridesFromLengths(lensVector), unaryOp};
}
else
{
*desc = {dataType, std::vector<std::size_t>(), std::vector<std::size_t>(), unaryOp};
}
}

return HIPTENSOR_STATUS_SUCCESS;
Expand Down
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
26 changes: 12 additions & 14 deletions library/src/reduction/hiptensor_reduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ namespace
using hiptensor::Logger;
auto& logger = Logger::instance();
char msg[2048];
if(!handle || !alpha || !A || !descA || !modeA || !beta || !C || !descC || !modeC || !D
|| !descD || !modeD)
if(!handle || !alpha || !A || !descA || !modeA || !beta || !C || !descC || !D || !descD)
{
auto errorCode = HIPTENSOR_STATUS_NOT_INITIALIZED;
auto printErrorMessage = [&logger, errorCode](const std::string& paramName) {
Expand Down Expand Up @@ -119,10 +118,6 @@ namespace
{
printErrorMessage("descC");
}
if(!modeC)
CongMa13 marked this conversation as resolved.
Show resolved Hide resolved
{
printErrorMessage("modeC");
}
if(!D)
{
printErrorMessage("D");
Expand All @@ -131,10 +126,6 @@ namespace
{
printErrorMessage("descD");
}
if(!modeD)
CongMa13 marked this conversation as resolved.
Show resolved Hide resolved
{
printErrorMessage("modeD");
}
return errorCode;
}

Expand Down Expand Up @@ -239,7 +230,7 @@ hiptensorStatus_t hiptensorReduction(const hiptensorHandle_t* handle,
auto errorCode = HIPTENSOR_STATUS_INTERNAL_ERROR;
snprintf(msg,
sizeof(msg),
"Internal Error : No Kernels Found (%s)",
"Internal Error : ReductionSolutionInstances is empty (%s)",
hiptensorGetErrorString(errorCode));
logger->logError("hiptensorReduction", msg);
return errorCode;
Expand All @@ -250,9 +241,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 All @@ -265,7 +263,7 @@ hiptensorStatus_t hiptensorReduction(const hiptensorHandle_t* handle,
auto errorCode = HIPTENSOR_STATUS_INTERNAL_ERROR;
snprintf(msg,
sizeof(msg),
"Internal Error : No Kernels Found (%s)",
"Internal Error : querySolutions returns 0 kernel. (%s)",
hiptensorGetErrorString(errorCode));
logger->logError("hiptensorReduction", msg);
return errorCode;
Expand Down Expand Up @@ -347,7 +345,7 @@ hiptensorStatus_t hiptensorReduction(const hiptensorHandle_t* handle,
auto errorCode = HIPTENSOR_STATUS_INTERNAL_ERROR;
snprintf(msg,
sizeof(msg),
"Selected kernel is unable to solve the problem (%s)",
"No kernel is able to solve the problem (%s)",
hiptensorGetErrorString(errorCode));
logger->logError("hiptensorReduction", msg);
return errorCode;
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
Loading
Loading