-
Notifications
You must be signed in to change notification settings - Fork 795
[ESIMD] Overloading sycl sin,cos,exp,log functions for ESIMD arguments #3717
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
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,71 @@ | ||
//==----------- builtins_esimd.hpp - SYCL ESIMD built-in functions ---------==// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include <CL/sycl/detail/boolean.hpp> | ||
#include <CL/sycl/detail/builtins.hpp> | ||
#include <CL/sycl/detail/common.hpp> | ||
#include <CL/sycl/detail/generic_type_traits.hpp> | ||
#include <CL/sycl/types.hpp> | ||
#include <sycl/ext/intel/experimental/esimd/detail/math_intrin.hpp> | ||
|
||
// TODO Decide whether to mark functions with this attribute. | ||
#define __NOEXC /*noexcept*/ | ||
|
||
__SYCL_INLINE_NAMESPACE(cl) { | ||
namespace sycl { | ||
|
||
// cos | ||
template <int SZ> | ||
ESIMD_NODEBUG ESIMD_INLINE __ESIMD_NS::simd<float, SZ> | ||
cos(__ESIMD_NS::simd<float, SZ> x) __NOEXC { | ||
#ifdef __SYCL_DEVICE_ONLY__ | ||
return __ESIMD_NS::detail::ocl_cos<SZ>(x.data()); | ||
#else | ||
return __esimd_cos<SZ>(x.data()); | ||
#endif // __SYCL_DEVICE_ONLY__ | ||
} | ||
|
||
// sin | ||
template <int SZ> | ||
ESIMD_NODEBUG ESIMD_INLINE __ESIMD_NS::simd<float, SZ> | ||
sin(__ESIMD_NS::simd<float, SZ> x) __NOEXC { | ||
#ifdef __SYCL_DEVICE_ONLY__ | ||
return __ESIMD_NS::detail::ocl_sin<SZ>(x.data()); | ||
#else | ||
return __esimd_sin<SZ>(x.data()); | ||
#endif // __SYCL_DEVICE_ONLY__ | ||
} | ||
|
||
// exp | ||
template <int SZ> | ||
ESIMD_NODEBUG ESIMD_INLINE __ESIMD_NS::simd<float, SZ> | ||
exp(__ESIMD_NS::simd<float, SZ> x) __NOEXC { | ||
#ifdef __SYCL_DEVICE_ONLY__ | ||
return __ESIMD_NS::detail::ocl_exp<SZ>(x.data()); | ||
#else | ||
return __esimd_exp<SZ>(x.data()); | ||
#endif // __SYCL_DEVICE_ONLY__ | ||
} | ||
|
||
// log | ||
template <int SZ> | ||
ESIMD_NODEBUG ESIMD_INLINE __ESIMD_NS::simd<float, SZ> | ||
log(__ESIMD_NS::simd<float, SZ> x) __NOEXC { | ||
#ifdef __SYCL_DEVICE_ONLY__ | ||
return __ESIMD_NS::detail::ocl_log<SZ>(x.data()); | ||
#else | ||
return __esimd_log<SZ>(x.data()); | ||
#endif // __SYCL_DEVICE_ONLY__ | ||
} | ||
|
||
} // namespace sycl | ||
} // __SYCL_INLINE_NAMESPACE(cl) | ||
|
||
#undef __NOEXC |
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
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,34 @@ | ||
// RUN: %clangxx -fsycl -c -fsycl-device-only -Xclang -emit-llvm %s -o - | FileCheck %s | ||
|
||
// This test checks the codegen for the basic usage of __ESIMD_SIMT_BEGIN - | ||
// __ESIMD_SIMT_END construct. | ||
|
||
#include <CL/sycl.hpp> | ||
#include <CL/sycl/INTEL/esimd.hpp> | ||
|
||
using namespace cl::sycl; | ||
using namespace sycl::ext::intel::experimental::esimd; | ||
|
||
// Wrapper for designating a scalar region of code that will be | ||
// vectorized by the backend compiler. | ||
#define SIMT_BEGIN(N, lane) \ | ||
[&]() SYCL_ESIMD_FUNCTION ESIMD_NOINLINE \ | ||
[[intel::sycl_esimd_vectorize(N)]] { \ | ||
int lane = __esimd_lane_id(); | ||
#define SIMT_END \ | ||
} \ | ||
(); | ||
|
||
// CHECK-LABEL: define dso_local spir_func void @_Z3fooi | ||
//CHECK: call spir_func void @_ZZ3fooiENKUlvE_clEv( | ||
SYCL_ESIMD_FUNCTION SYCL_EXTERNAL simd<int, 16> foo(int x) { | ||
simd<int, 16> v = 0; | ||
SIMT_BEGIN(16, lane) | ||
//CHECK: define internal spir_func void @_ZZ3fooiENKUlvE_clEv({{.*}}) {{.*}} #[[ATTR:[0-9]+]] | ||
//CHECK: %{{[0-9a-zA-Z_.]+}} = tail call spir_func i32 @_Z15__esimd_lane_idv() | ||
v.select<1, 0>(lane) = x++; | ||
SIMT_END | ||
return v; | ||
} | ||
|
||
//CHECK: attributes #[[ATTR]] = { {{.*}} "CMGenxSIMT"="16" {{.*}}} |
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,41 @@ | ||
// RUN: %clangxx -fsycl -c -fsycl-device-only -Xclang -emit-llvm %s -o - | FileCheck %s | ||
|
||
// This test checks the codegen for the following ESIMD APIs: | ||
// sin, cos, exp, log. | ||
|
||
#include <CL/sycl.hpp> | ||
#include <CL/sycl/INTEL/esimd.hpp> | ||
#include <CL/sycl/builtins_esimd.hpp> | ||
|
||
using namespace cl::sycl; | ||
using namespace sycl::ext::intel::experimental::esimd; | ||
|
||
// Math sin,cos,log,exp functions are translated into scalar __spirv_ocl_ calls | ||
SYCL_ESIMD_FUNCTION SYCL_EXTERNAL simd<float, 16> sycl_math(simd<float, 16> x) { | ||
simd<float, 16> v = 0; | ||
//CHECK: call spir_func float @_Z15__spirv_ocl_cosf | ||
v = sycl::cos(x); | ||
//CHECK: call spir_func float @_Z15__spirv_ocl_sinf | ||
v = sycl::sin(v); | ||
//CHECK: call spir_func float @_Z15__spirv_ocl_logf | ||
v = sycl::log(v); | ||
//CHECK: call spir_func float @_Z15__spirv_ocl_expf | ||
v = sycl::exp(v); | ||
return v; | ||
} | ||
|
||
// Math sin,cos,log,exp functions from esimd namespace are translated | ||
// into vector __esimd_ calls, which later translate into GenX intrinsics. | ||
SYCL_ESIMD_FUNCTION SYCL_EXTERNAL simd<float, 16> | ||
esimd_math(simd<float, 16> x) { | ||
simd<float, 16> v = 0; | ||
//CHECK: call spir_func <16 x float> @_Z11__esimd_cos | ||
v = esimd_cos(x); | ||
//CHECK: call spir_func <16 x float> @_Z11__esimd_sin | ||
v = esimd_sin(v); | ||
//CHECK: call spir_func <16 x float> @_Z11__esimd_log | ||
v = esimd_log(v); | ||
//CHECK: call spir_func <16 x float> @_Z11__esimd_exp | ||
v = esimd_exp(v); | ||
return v; | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for device it should be noexcept, as for all device functions, for host - same as usual SYCL host.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied it from
builtins.hpp
.