This repository was archived by the owner on Mar 28, 2023. It is now read-only.
  
  
  
            
  
    
      forked from llvm/llvm-test-suite
    
        
        - 
                Notifications
    You must be signed in to change notification settings 
- Fork 130
[SYCL] Tests for vec/marray math #1002
          
     Merged
      
      
    
  
     Merged
                    Changes from 3 commits
      Commits
    
    
            Show all changes
          
          
            25 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      f95793b
              
                tests for vec/marray math
              
              
                JackAKirk c7e2ff8
              
                Made template function improvement.
              
              
                JackAKirk b589c32
              
                format
              
              
                JackAKirk ab479c8
              
                split fp16 cases into new files.
              
              
                JackAKirk 9e2394e
              
                fixed queue constructor mistake.
              
              
                JackAKirk 80e6994
              
                format
              
              
                JackAKirk 1f0edf8
              
                use fp16 aspect in half_builtins.cpp
              
              
                JackAKirk 499c642
              
                removed unnecessary -fsycl-device-code-split=per_kernel.
              
              
                JackAKirk 86176da
              
                Merge branch 'intel' into math_marray_tests
              
              
                JackAKirk 3d03969
              
                write -> read (superficial change in context of test).
              
              
                JackAKirk 538c64b
              
                Removed float3 powr tests.
              
              
                JackAKirk e77ba69
              
                Removed failing test coverage for existing float3 functions.
              
              
                JackAKirk a3976b4
              
                Merge branch 'intel' into math_marray_tests
              
              
                JackAKirk 4f2dfe5
              
                Remove broken half/native cases.
              
              
                JackAKirk 29bd30b
              
                Merge branch 'intel' into math_marray_tests
              
              
                JackAKirk c1972f0
              
                Removed unused cases.
              
              
                JackAKirk 68e768d
              
                Merge branch 'math_marray_tests' of https://github.com/JackAKirk/llvm…
              
              
                JackAKirk 57f3329
              
                Add marray -fast-math test cases.
              
              
                JackAKirk a9efc86
              
                Removed initially proposed native and half_prec tests.
              
              
                JackAKirk f731c93
              
                Added back device-code-split.
              
              
                JackAKirk 505064c
              
                Remove host_runs.
              
              
                JackAKirk cfc1e91
              
                windows && level_zero marked unsupported.
              
              
                 ea6693d
              
                Mark opencl && windows unsupported.
              
              
                 5f91765
              
                Merge branch 'intel' into math_marray_tests
              
              
                JackAKirk 512a37a
              
                Added fp64 aspect check.
              
              
                 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,182 @@ | ||
| // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -fsycl-device-code-split=per_kernel %s -o %t.out | ||
| // RUN: %HOST_RUN_PLACEHOLDER %t.out | ||
| // RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
| // RUN: %GPU_RUN_PLACEHOLDER %t.out | ||
| // RUN: %ACC_RUN_PLACEHOLDER %t.out | ||
|  | ||
| // OpenCL CPU driver does not support cl_khr_fp16 extension for this reason this | ||
| // test is compiled with the -fsycl-device-code-split flag | ||
|  | ||
| #include <CL/sycl.hpp> | ||
| #include <cassert> | ||
|  | ||
| template <typename T, size_t N> | ||
| void assert_out_of_bound(sycl::marray<T, N> val, sycl::marray<T, N> lower, | ||
| sycl::marray<T, N> upper) { | ||
| for (int i = 0; i < N; i++) { | ||
| assert(lower[i] < val[i] && val[i] < upper[i]); | ||
| } | ||
| } | ||
|  | ||
| template <typename T> void assert_out_of_bound(T val, T lower, T upper) { | ||
| assert(sycl::all(lower < val && val < upper)); | ||
| } | ||
|  | ||
| template <> | ||
| void assert_out_of_bound<float>(float val, float lower, float upper) { | ||
| assert(lower < val && val < upper); | ||
| } | ||
|  | ||
| template <> | ||
| void assert_out_of_bound<sycl::half>(sycl::half val, sycl::half lower, | ||
| sycl::half upper) { | ||
| assert(lower < val && val < upper); | ||
| } | ||
|  | ||
| template <typename T> | ||
| void native_tanh_tester(sycl::queue q, T val, T up, T lo) { | ||
| T r = val; | ||
|  | ||
| #ifdef SYCL_EXT_ONEAPI_NATIVE_MATH | ||
| { | ||
| sycl::buffer<T, 1> BufR(&r, sycl::range<1>(1)); | ||
| q.submit([&](sycl::handler &cgh) { | ||
| auto AccR = BufR.template get_access<sycl::access::mode::read_write>(cgh); | ||
| cgh.single_task([=]() { | ||
| AccR[0] = sycl::ext::oneapi::experimental::native::tanh(AccR[0]); | ||
| }); | ||
| }); | ||
| } | ||
|  | ||
| assert_out_of_bound(r, up, lo); | ||
| #else | ||
| assert(!"SYCL_EXT_ONEAPI_NATIVE_MATH not supported"); | ||
| #endif | ||
| } | ||
|  | ||
| template <typename T> | ||
| void native_exp2_tester(sycl::queue q, T val, T up, T lo) { | ||
| T r = val; | ||
|  | ||
| #ifdef SYCL_EXT_ONEAPI_NATIVE_MATH | ||
| { | ||
| sycl::buffer<T, 1> BufR(&r, sycl::range<1>(1)); | ||
| q.submit([&](sycl::handler &cgh) { | ||
| auto AccR = BufR.template get_access<sycl::access::mode::read_write>(cgh); | ||
| cgh.single_task([=]() { | ||
| AccR[0] = sycl::ext::oneapi::experimental::native::exp2(AccR[0]); | ||
| }); | ||
| }); | ||
| } | ||
|  | ||
| assert_out_of_bound(r, up, lo); | ||
| #else | ||
| assert(!"SYCL_EXT_ONEAPI_NATIVE_MATH not supported"); | ||
| #endif | ||
| } | ||
|  | ||
| int main() { | ||
|  | ||
| sycl::queue q; | ||
|  | ||
| const double tv[16] = {-2.0, -1.5, -1.0, 0.0, 2.0, 1.5, 1.0, 0.0, | ||
| -1.7, 1.7, -1.2, 1.2, -3.0, 3.0, -10.0, 10.0}; | ||
| const double tl[16] = {-0.97, -0.91, -0.77, -0.1, 0.95, 0.89, 0.75, -0.1, | ||
| -0.94, 0.92, -0.84, 0.82, -1.0, 0.98, -1.10, 0.98}; | ||
| const double tu[16] = {-0.95, -0.89, -0.75, 0.1, 0.97, 0.91, 0.77, 0.1, | ||
| -0.92, 0.94, -0.82, 0.84, -0.98, 1.00, -0.98, 1.10}; | ||
|  | ||
| native_tanh_tester<float>(q, tv[0], tl[0], tu[0]); | ||
| native_tanh_tester<sycl::float2>(q, {tv[0], tv[1]}, {tl[0], tl[1]}, | ||
| {tu[0], tu[1]}); | ||
| native_tanh_tester<sycl::float3>( | ||
| q, {tv[0], tv[1], tv[2]}, {tl[0], tl[1], tl[2]}, {tu[0], tu[1], tu[2]}); | ||
|  | ||
| native_tanh_tester<sycl::float4>(q, {tv[0], tv[1], tv[2], tv[3]}, | ||
| {tl[0], tl[1], tl[2], tl[3]}, | ||
| {tu[0], tu[1], tu[2], tu[3]}); | ||
| native_tanh_tester<sycl::marray<float, 3>>( | ||
| q, {tv[0], tv[1], tv[2]}, {tl[0], tl[1], tl[2]}, {tu[0], tu[1], tu[2]}); | ||
| native_tanh_tester<sycl::marray<float, 4>>(q, {tv[0], tv[1], tv[2], tv[3]}, | ||
| {tl[0], tl[1], tl[2], tl[3]}, | ||
| {tu[0], tu[1], tu[2], tu[3]}); | ||
| native_tanh_tester<sycl::marray<float, 4>>(q, {tv[0], tv[1], tv[2], tv[3]}, | ||
| {tl[0], tl[1], tl[2], tl[3]}, | ||
| {tu[0], tu[1], tu[2], tu[3]}); | ||
| native_tanh_tester<sycl::float8>( | ||
| q, {tv[0], tv[1], tv[2], tv[3], tv[4], tv[5], tv[6], tv[7]}, | ||
| {tl[0], tl[1], tl[2], tl[3], tl[4], tl[5], tl[6], tl[7]}, | ||
| {tu[0], tu[1], tu[2], tu[3], tu[4], tu[5], tu[6], tu[7]}); | ||
| native_tanh_tester<sycl::float16>( | ||
| q, | ||
| {tv[0], tv[1], tv[2], tv[3], tv[4], tv[5], tv[6], tv[7], tv[8], tv[9], | ||
| tv[10], tv[11], tv[12], tv[13], tv[14], tv[15]}, | ||
| {tl[0], tl[1], tl[2], tl[3], tl[4], tl[5], tl[6], tl[7], tl[8], tl[9], | ||
| tl[10], tl[11], tl[12], tl[13], tl[14], tl[15]}, | ||
| {tu[0], tu[1], tu[2], tu[3], tu[4], tu[5], tu[6], tu[7], tu[8], tu[9], | ||
| tu[10], tu[11], tu[12], tu[13], tu[14], tu[15]}); | ||
|  | ||
| if (q.get_device().has(sycl::aspect::fp16)) { | ||
|  | ||
| native_tanh_tester<sycl::half>(q, tv[0], tl[0], tu[0]); | ||
| native_tanh_tester<sycl::half2>(q, {tv[0], tv[1]}, {tl[0], tl[1]}, | ||
| {tu[0], tu[1]}); | ||
| native_tanh_tester<sycl::half3>( | ||
| q, {tv[0], tv[1], tv[2]}, {tl[0], tl[1], tl[2]}, {tu[0], tu[1], tu[2]}); | ||
| native_tanh_tester<sycl::marray<sycl::half, 3>>( | ||
| q, {tv[0], tv[1], tv[2]}, {tl[0], tl[1], tl[2]}, {tu[0], tu[1], tu[2]}); | ||
| native_tanh_tester<sycl::half4>(q, {tv[0], tv[1], tv[2], tv[3]}, | ||
| {tl[0], tl[1], tl[2], tl[3]}, | ||
| {tu[0], tu[1], tu[2], tu[3]}); | ||
| native_tanh_tester<sycl::marray<sycl::half, 4>>( | ||
| q, {tv[0], tv[1], tv[2], tv[3]}, {tl[0], tl[1], tl[2], tl[3]}, | ||
| {tu[0], tu[1], tu[2], tu[3]}); | ||
| native_tanh_tester<sycl::half8>( | ||
| q, {tv[0], tv[1], tv[2], tv[3], tv[4], tv[5], tv[6], tv[7]}, | ||
| {tl[0], tl[1], tl[2], tl[3], tl[4], tl[5], tl[6], tl[7]}, | ||
| {tu[0], tu[1], tu[2], tu[3], tu[4], tu[5], tu[6], tu[7]}); | ||
| native_tanh_tester<sycl::half16>( | ||
| q, | ||
| {tv[0], tv[1], tv[2], tv[3], tv[4], tv[5], tv[6], tv[7], tv[8], tv[9], | ||
| tv[10], tv[11], tv[12], tv[13], tv[14], tv[15]}, | ||
| {tl[0], tl[1], tl[2], tl[3], tl[4], tl[5], tl[6], tl[7], tl[8], tl[9], | ||
| tl[10], tl[11], tl[12], tl[13], tl[14], tl[15]}, | ||
| {tu[0], tu[1], tu[2], tu[3], tu[4], tu[5], tu[6], tu[7], tu[8], tu[9], | ||
| tu[10], tu[11], tu[12], tu[13], tu[14], tu[15]}); | ||
|  | ||
| const double ev[16] = {-2.0, -1.5, -1.0, 0.0, 2.0, 1.5, 1.0, 0.0, | ||
| -2.0, -1.5, -1.0, 0.0, 2.0, 1.5, 1.0, 0.0}; | ||
| const double el[16] = {0.1, 0.34, 0.4, -0.9, 3.9, 2.7, 1.9, -0.9, | ||
| 0.1, 0.34, 0.4, -0.9, 3.9, 2.7, 1.9, -0.9}; | ||
| const double eu[16] = {0.3, 0.36, 0.6, 1.1, 4.1, 2.9, 2.1, 1.1, | ||
| 0.3, 0.36, 0.6, 1.1, 4.1, 2.9, 2.1, 1.1}; | ||
|  | ||
| native_exp2_tester<sycl::half>(q, ev[0], el[0], eu[0]); | ||
| native_exp2_tester<sycl::half2>(q, {ev[0], ev[1]}, {el[0], el[1]}, | ||
| {eu[0], eu[1]}); | ||
| native_exp2_tester<sycl::half3>( | ||
| q, {ev[0], ev[1], ev[2]}, {el[0], el[1], el[2]}, {eu[0], eu[1], eu[2]}); | ||
| native_exp2_tester<sycl::half4>(q, {ev[0], ev[1], ev[2], ev[3]}, | ||
| {el[0], el[1], el[2], el[3]}, | ||
| {eu[0], eu[1], eu[2], eu[3]}); | ||
| native_exp2_tester<sycl::marray<sycl::half, 3>>( | ||
| q, {ev[0], ev[1], ev[2]}, {el[0], el[1], el[2]}, {eu[0], eu[1], eu[2]}); | ||
| native_exp2_tester<sycl::marray<sycl::half, 4>>( | ||
| q, {ev[0], ev[1], ev[2], ev[3]}, {el[0], el[1], el[2], el[3]}, | ||
| {eu[0], eu[1], eu[2], eu[3]}); | ||
| native_exp2_tester<sycl::half8>( | ||
| q, {ev[0], ev[1], ev[2], ev[3], ev[4], ev[5], ev[6], ev[7]}, | ||
| {el[0], el[1], el[2], el[3], el[4], el[5], el[6], el[7]}, | ||
| {eu[0], eu[1], eu[2], eu[3], eu[4], eu[5], eu[6], eu[7]}); | ||
| native_exp2_tester<sycl::half16>( | ||
| q, | ||
| {ev[0], ev[1], ev[2], ev[3], ev[4], ev[5], ev[6], ev[7], ev[8], ev[9], | ||
| ev[10], ev[11], ev[12], ev[13], ev[14], ev[15]}, | ||
| {el[0], el[1], el[2], el[3], el[4], el[5], el[6], el[7], el[8], el[9], | ||
| el[10], el[11], el[12], el[13], el[14], el[15]}, | ||
| {eu[0], eu[1], eu[2], eu[3], eu[4], eu[5], eu[6], eu[7], eu[8], eu[9], | ||
| eu[10], eu[11], eu[12], eu[13], eu[14], eu[15]}); | ||
| } | ||
|  | ||
| return 0; | ||
| } | 
      
      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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.