Skip to content

Commit

Permalink
Add conversion code for Float16 that was missed in #8174 (#8178)
Browse files Browse the repository at this point in the history
* Add conversion code for Float16 that was missed in #8174

* Don't sniff for _Float16 when building ASAN

* Update HalideRuntime.h
  • Loading branch information
steven-johnson committed Apr 5, 2024
1 parent 3b8a532 commit 7d99357
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/runtime/HalideRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ extern "C" {

#ifndef COMPILING_HALIDE_RUNTIME

// ASAN builds can cause linker errors for Float16, so sniff for that and
// don't enable it by default.
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#define HALIDE_RUNTIME_ASAN_DETECTED
#endif
#endif

#if defined(__SANITIZE_ADDRESS__) && !defined(HALIDE_RUNTIME_ASAN_DETECTED)
#define HALIDE_RUNTIME_ASAN_DETECTED
#endif

#if !defined(HALIDE_RUNTIME_ASAN_DETECTED)

// clang had _Float16 added as a reserved name in clang 8, but
// doesn't actually support it on most platforms until clang 15.
// Ideally there would be a better way to detect if the type
Expand All @@ -108,6 +122,8 @@ extern "C" {
#endif
#endif

#endif // !HALIDE_RUNTIME_ASAN_DETECTED

#endif // !COMPILING_HALIDE_RUNTIME

/** \file
Expand Down
8 changes: 8 additions & 0 deletions tools/halide_image_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -2227,6 +2227,10 @@ struct ImageTypeConversion {

const halide_type_t src_type = src.type();
switch (src_type.element_of().as_u32()) {
#ifdef HALIDE_CPP_COMPILER_HAS_FLOAT16
case halide_type_t(halide_type_float, 16).as_u32():
return convert_image<DstElemType>(src.template as<_Float16, AnyDims>());
#endif
case halide_type_t(halide_type_float, 32).as_u32():
return convert_image<DstElemType>(src.template as<float, AnyDims>());
case halide_type_t(halide_type_float, 64).as_u32():
Expand Down Expand Up @@ -2272,6 +2276,10 @@ struct ImageTypeConversion {
// Call the appropriate static-to-static conversion routine
// based on the desired dst type.
switch (dst_type.element_of().as_u32()) {
#ifdef HALIDE_CPP_COMPILER_HAS_FLOAT16
case halide_type_t(halide_type_float, 16).as_u32():
return convert_image<_Float16>(src);
#endif
case halide_type_t(halide_type_float, 32).as_u32():
return convert_image<float>(src);
case halide_type_t(halide_type_float, 64).as_u32():
Expand Down

0 comments on commit 7d99357

Please sign in to comment.