Skip to content

[SYCL][Test] Devicelib test #1256

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 21 commits into from
Apr 15, 2020
Merged

[SYCL][Test] Devicelib test #1256

merged 21 commits into from
Apr 15, 2020

Conversation

haonanya
Copy link
Contributor

@haonanya haonanya commented Mar 6, 2020

  1. add test for all math function.
  2. In llvm/sycl/source/detail/devicelib/CMakeLists.txt, libsycl-cmath.o depends on device_math.h,
    modify here.

…math.o depends on device_math.h, modify here

Signed-off-by: haonanya <[email protected]>
@haonanya haonanya changed the title [SYCL] Devicelib test [SYCL][Test] Devicelib test Mar 6, 2020
@jinge90
Copy link
Contributor

jinge90 commented Mar 6, 2020

Hi, @bader , @asavonic , @andykaylor
We plan to upload more tests for cmath device library, could you help review?
Thank you very much.

else {
T max_v = std::fmax(std::abs(x), std::abs(y));
return (std::abs(x - y) / max_v) <
std::numeric_limits<T>::epsilon() * 100;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::numeric_limits<T>::epsilon() * 100;
std::numeric_limits<T>::epsilon() * 100;

Why 100?
Different math functions have different accuracy requirements and this seems to be too relax.

The bigger problem is that single threshold is applied to all functions. I think it should the threshold should be function dependent. Not sure if we want to checks the requirements set by the specification, but current value seems to be too relaxed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Alexey.
In fact, we added those cases only to test basic functionality of math functions provided by device library. The accuracy is not meant to be covered by these tests, all those input values of cmath functions are very simple ones. In fact, we are doing some accuracy tests on device library's and , all input will be much more complicated and different threshold are used and compared.
Thank you very much.

Signed-off-by: haonanya <[email protected]>
Comment on lines 9 to 14
// At least one input is nan
if (std::isnan(x) || std::isnan(y))
ret = std::isnan(x) && std::isnan(y);

// At least one input is inf
else if (std::isinf(x) || std::isinf(y))
Copy link
Contributor

@bader bader Mar 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the code with early exit more readable than this version.

Suggested change
// At least one input is nan
if (std::isnan(x) || std::isnan(y))
ret = std::isnan(x) && std::isnan(y);
// At least one input is inf
else if (std::isinf(x) || std::isinf(y))
// At least one input is nan
if (std::isnan(x) || std::isnan(y))
return std::isnan(x) && std::isnan(y);
// At least one input is inf
if (std::isinf(x) || std::isinf(y))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix for fixing this, but could you apply this comment to the file, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Alexey.
I am sorry to make things complicated. I am new user.
Thanks for your patience.

bader
bader previously approved these changes Mar 16, 2020
@bader
Copy link
Contributor

bader commented Mar 16, 2020

Please, fix code formatting issues.

@@ -1,25 +1,33 @@
#ifndef MATH_UTILS
#include <complex>
#include <limits>
using namespace std;
// T must be float-point type
template <typename T>
bool is_about_FP(T x, T y) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you are here, could you add a comment explaining what this function... is_about? :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Ronan.
Since it is not proper to compare float point using operator ==, this function measure whether the result of cmath function from kernel is close to the reference and machine epsilon is used as threshold in this function.
Thanks very much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah quite clearer with a comment! :-)

Then perhaps a clearer name for the function would help...

fuzzy_equal_fp ? approx_equal_fp ? I am not an native English speaker so I am not very helpful here...

haonanya and others added 2 commits March 18, 2020 11:38
Modify code to follow coding standards

Co-Authored-By: Ronan Keryell <[email protected]>
Signed-off-by: haonanya <[email protected]>
@@ -1,25 +1,33 @@
#ifndef MATH_UTILS
#include <complex>
#include <limits>
using namespace std;
// T must be float-point type
template <typename T>
bool is_about_FP(T x, T y) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah quite clearer with a comment! :-)

Then perhaps a clearer name for the function would help...

fuzzy_equal_fp ? approx_equal_fp ? I am not an native English speaker so I am not very helpful here...

}
}
return ret;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this kind of code it is probably clearer to remove ret and just have as many early return as required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for your comment, early return is applied to new commit and approx_equal_fp is used as the name of float point comparison.

@bader
Copy link
Contributor

bader commented Mar 22, 2020

@haonanya, please, resolve conflicts.

Copy link
Contributor

@bader bader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment.
Other than that - looks good to me.

if (std::isinf(x) || std::isinf(y))
return (x == y);

// two finite
else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, don't use else after return.
Apply here and all the cases below.

@haonanya haonanya requested a review from romanovvlad as a code owner April 7, 2020 13:19
@bader
Copy link
Contributor

bader commented Apr 7, 2020

LGTM, but I'd like to have reviews from @asavonic and @romanovvlad.
Thanks!

romanovvlad
romanovvlad previously approved these changes Apr 8, 2020
@@ -0,0 +1,113 @@
// UNSUPPORTED: windows
// RUN: %clangxx -fsycl -c %s -o %t.o
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/libsycl-cmath-fp64.o -o %t.out
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a RUN line for execution here and in all other tests.
Otherwise this just tests for compilation and no runtime validation is performed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are going to run the compiled program, they should be moved to end-to-end testing.

Copy link
Contributor

@jinge90 jinge90 Apr 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @andykaylor and @asavonic
Could we enable the run command for cmath tests on CPU device currently?
For GPU, only OCL RT can work. For CPU, all cmath and complex tests should work in theory but OCL CPU RT has an issue which will lead to crash on some platforms, the fix has not been merged into latest OCL CPU RT, so we may encounter some unexpected crash if enable complex tests.
Thank you very much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andykaylor

If these are going to run the compiled program, they should be moved to end-to-end testing.

Most of the tests in sycl/test directory have RUN lines to test on available devices.
This test in particular has a lot of runtime asserts.

Could we enable the run command for cmath tests on CPU device currently?

I think they should be enabled for all devices you expect this code to work. I assume it should work for CPU and GPU, right? FPGA is probably not going work, because AOT compilation is not support for device libraries yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a test doesn't work on some platform due to a bug, it should be disabled temporarily.

@bader bader requested a review from asavonic April 9, 2020 12:22
@bader
Copy link
Contributor

bader commented Apr 10, 2020

@asavonic, ping.

@bader bader merged commit ec80987 into intel:sycl Apr 15, 2020
alexbatashev pushed a commit to alexbatashev/llvm that referenced this pull request Apr 21, 2020
…c_abi_checks

* origin/sycl:
  [SYCL][Driver] Enforce unique filenames when -save-temps is used (intel#1545)
  [SYCL] [xmethods] Allow replacing xmethod script (intel#1532)
  [SYCL] Add tests for inline asm feature (intel#1444)
  [SYCL][Doc] Add device_specific_kernel_queries extension. (intel#1540)
  [SYCL][USM] Remove unused header and unnecessary includes (intel#1537)
  Fix check-llvm dependencies (intel#1547)
  [SYCL] Add __SYCL_EXPORT to declaration of contextSetExtendedDeleter (intel#1531)
  [SYCL][Doc] Add static local memory query extension. (intel#1539)
  [SYCL][Doc] Add sycl_bitcast extension (intel#1541)
  [SYCL][NFC] Temporarily disable sporadically failing test (intel#1533)
  [SYCL][NFC] Adjust codeowners for sycl directory (intel#1529)
  [SYCL] Fix processing of spec consts referenced twice (intel#1524)
  [SYCL] Use correct macro name in export.hpp (intel#1527)
  [Driver][NFC] Fix -help information for -Xs options (intel#1530)
  [SYCL][Doc] Add Graph Scheduler design documentation (intel#1457)
  [SYCL] Add diagnostics for long double in device code (intel#1512)
  [SYCL] Add a mutex to state-modifying program functions (intel#1204)
  [SYCL][Test] Add Devicelib tests (intel#1256)
  [SYCL] Refactor semantic checks for variable types (intel#1513)
bb-sycl pushed a commit that referenced this pull request May 20, 2022
The types of lower bound, upper bound, and step are converted into the
type of the loop variable if necessary. OpenMP runtime requires 32-bit
or 64-bit loop variables. OpenMP loop iteration variable cannot have
more than 64 bits size and will be narrowed.

This patch is part of upstreaming code from the fir-dev branch of
https://github.com/flang-compiler/f18-llvm-project. (#1256)

Co-authored-by: kiranchandramohan <[email protected]>

Reviewed By: kiranchandramohan, shraiysh

Differential Revision: https://reviews.llvm.org/D125740
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants