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

Fix OpenCL positive and negative INF constants. #8266

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 8 additions & 3 deletions src/CodeGen_OpenCL_Dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "EliminateBoolVectors.h"
#include "EmulateFloat16Math.h"
#include "ExprUsesVar.h"
#include "Float16.h"
#include "IRMutator.h"
#include "IROperator.h"
#include "Simplify.h"
Expand Down Expand Up @@ -1183,11 +1184,15 @@ void CodeGen_OpenCL_Dev::init_module() {
}

if (target.has_feature(Target::CLHalf)) {
const uint16_t nan_f16 = float16_t::make_nan().to_bits();
const uint16_t neg_inf_f16 = float16_t::make_negative_infinity().to_bits();
const uint16_t inf_f16 = float16_t::make_infinity().to_bits();

src_stream << "#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
<< "inline half half_from_bits(unsigned short x) {return __builtin_astype(x, half);}\n"
<< "inline half nan_f16() { return half_from_bits(32767); }\n"
<< "inline half neg_inf_f16() { return half_from_bits(31744); }\n"
<< "inline half inf_f16() { return half_from_bits(64512); }\n"
<< "inline half nan_f16() { return half_from_bits(" << nan_f16 << "); }\n"
<< "inline half neg_inf_f16() { return half_from_bits(" << neg_inf_f16 << "); }\n"
<< "inline half inf_f16() { return half_from_bits(" << inf_f16 << "); }\n"
<< "inline bool is_nan_f16(half x) {return isnan(x); }\n"
<< "inline bool is_inf_f16(half x) {return isinf(x); }\n"
<< "inline bool is_finite_f16(half x) {return isfinite(x); }\n"
Expand Down
5 changes: 3 additions & 2 deletions test/correctness/gpu_f16_intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ using namespace Halide;
int main(int argc, char *argv[]) {

auto target = get_jit_target_from_environment();
if (!target.has_feature(Target::Metal)) {
printf("[SKIP] No metal target enabled.\n");
if (!target.has_feature(Target::Metal) &&
!target.features_all_of({Target::OpenCL, Target::CLHalf})) {
printf("[SKIP] Test only applies to Metal and OpenCL+CLHalf.\n");
return 0;
}

Expand Down
Loading