-
Notifications
You must be signed in to change notification settings - Fork 794
[SYCL] Add sycl cpp header for imf libdevice API #6487
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ff52930
[SYCL] Add sycl cpp header for imf libdevice API
jinge90 30a560e
Merge remote-tracking branch 'origin/sycl' into imf_sycl_header
jinge90 6b550dc
add imf APIs to top level sycl headers
jinge90 42951ca
disable IMF APIs for NVPTX
jinge90 cfc5237
remove imf defines from sycl.hpp
jinge90 40c215a
Dispatch to corresponding C imf APIs in template function
jinge90 d9c2426
use compile-time if
jinge90 a9aee9a
Merge remote-tracking branch 'origin/sycl' into imf_sycl_header
jinge90 aba34a7
Address some review comments
jinge90 190b9ed
Use std::enable_if_t to replace static_assert
jinge90 aa4d5ac
Merge remote-tracking branch 'upstream/sycl' into imf_sycl_header
jinge90 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//==------------- math.hpp - Intel specific math API -----------------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// The main header of Intel specific math API | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
#include <sycl/half_type.hpp> | ||
#include <type_traits> | ||
|
||
// _iml_half_internal is internal representation for fp16 type used in intel | ||
// math device library. The definition here should align with definition in | ||
// https://github.com/intel/llvm/blob/sycl/libdevice/imf_half.hpp | ||
#if defined(__SPIR__) | ||
using _iml_half_internal = _Float16; | ||
#else | ||
using _iml_half_internal = uint16_t; | ||
#endif | ||
|
||
extern "C" { | ||
float __imf_saturatef(float); | ||
float __imf_copysignf(float, float); | ||
double __imf_copysign(double, double); | ||
_iml_half_internal __imf_copysignf16(_iml_half_internal, _iml_half_internal); | ||
}; | ||
|
||
namespace sycl { | ||
__SYCL_INLINE_VER_NAMESPACE(_V1) { | ||
namespace ext { | ||
namespace intel { | ||
namespace math { | ||
|
||
#if __cplusplus >= 201703L | ||
template <typename Tp> | ||
std::enable_if_t<std::is_same_v<Tp, float>, float> saturate(Tp x) { | ||
return __imf_saturatef(x); | ||
} | ||
|
||
template <typename Tp> | ||
std::enable_if_t<std::is_same_v<Tp, float>, float> copysign(Tp x, Tp y) { | ||
return __imf_copysignf(x, y); | ||
} | ||
|
||
template <typename Tp> | ||
std::enable_if_t<std::is_same_v<Tp, double>, double> copysign(Tp x, Tp y) { | ||
return __imf_copysign(x, y); | ||
} | ||
|
||
template <typename Tp> | ||
std::enable_if_t<std::is_same_v<Tp, sycl::half>, sycl::half> copysign(Tp x, | ||
Tp y) { | ||
static_assert(sizeof(sycl::half) == sizeof(_iml_half_internal), | ||
"sycl::half is not compatible with _iml_half_internal."); | ||
_iml_half_internal xi = __builtin_bit_cast(_iml_half_internal, x); | ||
_iml_half_internal yi = __builtin_bit_cast(_iml_half_internal, y); | ||
return __builtin_bit_cast(sycl::half, __imf_copysignf16(xi, yi)); | ||
} | ||
|
||
#endif | ||
} // namespace math | ||
} // namespace intel | ||
} // namespace ext | ||
} // __SYCL_INLINE_VER_NAMESPACE(_V1) | ||
} // namespace sycl |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.