- 
                Notifications
    You must be signed in to change notification settings 
- Fork 794
[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
                    Changes from 10 commits
      Commits
    
    
            Show all changes
          
          
            21 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      c3a5cd5
              
                [SYCL] add test for all math function.
              
              
                haonanya1 1816430
              
                [SYCL] in llvm/sycl/source/detail/devicelib/CMakeLists.txt, libsycl-c…
              
              
                haonanya1 5540691
              
                [SYCL] Put all math function calls into a single kernel.
              
              
                haonanya1 79dce3e
              
                [SYCL] Remove using namespace std in math_utils.hpp
              
              
                haonanya1 3836b41
              
                [SYCL] modify std_complex_math_fp64_test.cpp and std_complex_math_tes…
              
              
                haonanya1 e28efb4
              
                [SYCL] [Test] Put all math function calls into a single kernel
              
              
                haonanya1 1251e56
              
                [SYCL] [Test] Deal with nan and inf input in is_about_FP function in …
              
              
                haonanya1 9d62247
              
                [SYCL] Format code
              
              
                haonanya1 b670056
              
                [SYCL] Code clean
              
              
                haonanya1 fd16ef2
              
                [SYCL] [Test] Improve readability for math_utils.hpp
              
              
                haonanya1 764518e
              
                Update sycl/test/devicelib/math_utils.hpp
              
              
                haonanya 10c938b
              
                [SYCL] Add comment for is_about_FP function in math_utils.hpp
              
              
                haonanya1 e8bfe40
              
                [SYCL] [Test] Rename is_about_FP function and remove ret to use early…
              
              
                haonanya1 014d3b2
              
                [SYCL] [Test] Rename complex compare function.
              
              
                haonanya1 6ef6fac
              
                [SYCL] [Test] There is a rename for float point compare in math_utils…
              
              
                haonanya1 0e84acf
              
                Merge branch 'sycl' into devicelibTest
              
              
                haonanya1 d6cd3fc
              
                Merge branch 'sycl' into devicelibTest
              
              
                haonanya1 88fc254
              
                Fix use else after return issue
              
              
                haonanya1 048e5d0
              
                [SYCL][Test] Enable cmath lit test.
              
              
                haonanya1 e8ac45e
              
                [SYCL][Test] Enable Host device for math_override.cpp.
              
              
                haonanya1 a54c5f1
              
                [SYCL] [Test] Fix format issue.
              
              
                haonanya1 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
    
  
  
    
              
  
    
      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,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 | ||
| #include <CL/sycl.hpp> | ||
| #include <cmath> | ||
| #include <iostream> | ||
| #include "math_utils.hpp" | ||
|  | ||
| namespace s = cl::sycl; | ||
| constexpr s::access::mode sycl_read = s::access::mode::read; | ||
| constexpr s::access::mode sycl_write = s::access::mode::write; | ||
|  | ||
| #define TEST_NUM 38 | ||
|  | ||
| double ref[TEST_NUM] = { | ||
| 1, 0, 0, 0, 0, 0, 0, 1, 1, 0.5, | ||
| 0, 2, 0, 0, 1, 0, 2, 0, 0, 0, | ||
| 0, 0, 1, 0, 1, 2, 0, 1, 2, 5, | ||
| 0, 0, 0, 0, 0.5, 0.5, NAN, NAN,}; | ||
|  | ||
| double refIptr = 1; | ||
|  | ||
| template <class T> | ||
| void device_cmath_test(s::queue &deviceQueue) { | ||
| s::range<1> numOfItems{TEST_NUM}; | ||
| T result[TEST_NUM] = {-1}; | ||
|  | ||
| // Variable exponent is an integer value to store the exponent in frexp function | ||
| int exponent = -1; | ||
|  | ||
| // Variable iptr stores the integral part of float point in modf function | ||
| T iptr = -1; | ||
|  | ||
| // Variable quo stores the sign and some bits of x/y in remquo function | ||
| int quo = -1; | ||
| { | ||
| s::buffer<T, 1> buffer1(result, numOfItems); | ||
| s::buffer<int, 1> buffer2(&exponent, s::range<1>{1}); | ||
| s::buffer<T, 1> buffer3(&iptr, s::range<1>{1}); | ||
| s::buffer<int, 1> buffer4(&quo, s::range<1>{1}); | ||
| deviceQueue.submit([&](cl::sycl::handler &cgh) { | ||
| auto res_access = buffer1.template get_access<sycl_write>(cgh); | ||
| auto exp_access = buffer2.template get_access<sycl_write>(cgh); | ||
| auto iptr_access = buffer3.template get_access<sycl_write>(cgh); | ||
| auto quo_access = buffer4.template get_access<sycl_write>(cgh); | ||
| cgh.single_task<class DeviceMathTest>([=]() { | ||
| int i = 0; | ||
| res_access[i++] = std::cos(0.0); | ||
| res_access[i++] = std::sin(0.0); | ||
| res_access[i++] = std::log(1.0); | ||
| res_access[i++] = std::acos(1.0); | ||
| res_access[i++] = std::asin(0.0); | ||
| res_access[i++] = std::atan(0.0); | ||
| res_access[i++] = std::atan2(0.0, 1.0); | ||
| res_access[i++] = std::cosh(0.0); | ||
| res_access[i++] = std::exp(0.0); | ||
| res_access[i++] = std::fmod(1.5, 1.0); | ||
| res_access[i++] = std::frexp(0.0, &exp_access[0]); | ||
| res_access[i++] = std::ldexp(1.0, 1); | ||
| res_access[i++] = std::log10(1.0); | ||
| res_access[i++] = std::modf(1.0, &iptr_access[0]); | ||
| res_access[i++] = std::pow(1.0, 1.0); | ||
| res_access[i++] = std::sinh(0.0); | ||
| res_access[i++] = std::sqrt(4.0); | ||
| res_access[i++] = std::tan(0.0); | ||
| res_access[i++] = std::tanh(0.0); | ||
| res_access[i++] = std::acosh(1.0); | ||
| res_access[i++] = std::asinh(0.0); | ||
| res_access[i++] = std::atanh(0.0); | ||
| res_access[i++] = std::cbrt(1.0); | ||
| res_access[i++] = std::erf(0.0); | ||
| res_access[i++] = std::erfc(0.0); | ||
| res_access[i++] = std::exp2(1.0); | ||
| res_access[i++] = std::expm1(0.0); | ||
| res_access[i++] = std::fdim(1.0, 0.0); | ||
| res_access[i++] = std::fma(1.0, 1.0, 1.0); | ||
| res_access[i++] = std::hypot(3.0, 4.0); | ||
| res_access[i++] = std::ilogb(1.0); | ||
| res_access[i++] = std::log1p(0.0); | ||
| res_access[i++] = std::log2(1.0); | ||
| res_access[i++] = std::logb(1.0); | ||
| res_access[i++] = std::remainder(0.5, 1.0); | ||
| res_access[i++] = std::remquo(0.5, 1.0, &quo_access[0]); | ||
| T a = NAN; | ||
| res_access[i++] = std::tgamma(a); | ||
| res_access[i++] = std::lgamma(a); | ||
| }); | ||
| }); | ||
| } | ||
|  | ||
| // Compare result with reference | ||
| for (int i = 0; i < TEST_NUM; ++i) { | ||
| assert(is_about_FP(result[i], ref[i])); | ||
| } | ||
|  | ||
| // Test modf integral part | ||
| assert(is_about_FP(iptr, refIptr)); | ||
|  | ||
| // Test frexp exponent | ||
| assert(exponent == 0); | ||
|  | ||
| // Test remquo sign | ||
| assert(quo == 0); | ||
| } | ||
|  | ||
| int main() { | ||
| s::queue deviceQueue; | ||
| if (deviceQueue.get_device().has_extension("cl_khr_fp64")) { | ||
| device_cmath_test<double>(deviceQueue); | ||
| std::cout << "Pass" << std::endl; | ||
| } | ||
| return 0; | ||
| } | ||
  
    
      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 was deleted.
      
      Oops, something went wrong.
      
    
  
      
      Oops, something went wrong.
        
    
  
  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.
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.
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.
If these are going to run the compiled program, they should be moved to end-to-end testing.
Uh oh!
There was an error while loading. Please reload this page.
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.
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.
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.
@andykaylor
Most of the tests in
sycl/testdirectory have RUN lines to test on available devices.This test in particular has a lot of runtime asserts.
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.
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.
If a test doesn't work on some platform due to a bug, it should be disabled temporarily.