- 
                Notifications
    
You must be signed in to change notification settings  - Fork 794
 
[SYCL] Add support for free function kernel builtins #15938
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
          
          
            5 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      e3f3cbf
              
                [SYCL] Add support for free function kernel builtins
              
              
                premanandrao 0cf3ab8
              
                Fix clang-format errors
              
              
                premanandrao 4fa3fbb
              
                Fix clang-format errors (again)
              
              
                premanandrao 86a696d
              
                Fix tests to work around Windows restriction
              
              
                premanandrao e4face5
              
                Rebase to avoid conflicts
              
              
                premanandrao 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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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,79 @@ | ||
| // RUN: %clang_cc1 -internal-isystem %S/Inputs -fsycl-is-device -triple spir64-unknown-unknown -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s | ||
| 
     | 
||
| // This test tests the builtin __builtin_sycl_is_kernel | ||
| 
     | 
||
| #include "sycl.hpp" | ||
| 
     | 
||
| using namespace sycl; | ||
| queue q; | ||
| 
     | 
||
| __attribute__((sycl_device)) | ||
| [[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 0)]] | ||
| void sstk_free_func() { | ||
| } | ||
| 
     | 
||
| template <typename T> | ||
| [[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 4)]] | ||
| void sstk_free_func_tmpl(T *ptr) { | ||
| for (int i = 0; i <= 7; i++) | ||
| ptr[i] = i + 11; | ||
| } | ||
| 
     | 
||
| __attribute__((sycl_device)) | ||
| [[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 1)]] | ||
| void ovl_free_func(int *ptr) { | ||
| for (int i = 0; i <= 7; i++) | ||
| ptr[i] = i; | ||
| } | ||
| 
     | 
||
| __attribute__((sycl_device)) | ||
| [[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 1)]] | ||
| void ovl_free_func(int *ptr, int val) { | ||
| for (int i = 0; i <= 7; i++) | ||
| ptr[i] = i + val; | ||
| } | ||
| 
     | 
||
| __attribute__((sycl_device)) | ||
| [[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 4)]] | ||
| void sndrk_free_func() { | ||
| } | ||
| 
     | 
||
| void func() {} | ||
| 
     | 
||
| void foo() { | ||
| bool b1 = __builtin_sycl_is_kernel(sstk_free_func); | ||
| // CHECK: store i8 1, ptr addrspace(4) %b1{{.*}}, align 1 | ||
| bool b2 = __builtin_sycl_is_kernel(*sstk_free_func); | ||
| // CHECK: store i8 1, ptr addrspace(4) %b2{{.*}}, align 1 | ||
| bool b3 = __builtin_sycl_is_kernel(&sstk_free_func); | ||
| // CHECK: store i8 1, ptr addrspace(4) %b3{{.*}}, align 1 | ||
| bool b4 = __builtin_sycl_is_kernel(func); | ||
| // CHECK: store i8 0, ptr addrspace(4) %b4{{.*}}, align 1 | ||
| bool b5 = __builtin_sycl_is_kernel(sndrk_free_func); | ||
| // CHECK: store i8 1, ptr addrspace(4) %b5{{.*}}, align 1 | ||
| 
     | 
||
| // Constexpr forms of the valid cases. | ||
| constexpr bool b6 = __builtin_sycl_is_kernel(sstk_free_func); // Okay and true. | ||
| // CHECK: store i8 1, ptr addrspace(4) %b6{{.*}}, align 1 | ||
| constexpr bool b7 = __builtin_sycl_is_kernel(func); // Okay, but false. | ||
| // CHECK: store i8 0, ptr addrspace(4) %b7{{.*}}, align 1 | ||
| constexpr bool b8 = __builtin_sycl_is_kernel(sndrk_free_func); // Okay, but false. | ||
| // CHECK: store i8 1, ptr addrspace(4) %b8{{.*}}, align 1 | ||
| 
     | 
||
| // Test function template. | ||
| constexpr bool b9 = __builtin_sycl_is_kernel((void(*)(int *))sstk_free_func_tmpl<int>); // Okay | ||
| // CHECK: store i8 1, ptr addrspace(4) %b9{{.*}}, align 1 | ||
| 
     | 
||
| // Test overloaded functions. | ||
| constexpr bool b10 = __builtin_sycl_is_kernel((void(*)(int *))ovl_free_func); // Okay | ||
| // CHECK: store i8 1, ptr addrspace(4) %b10{{.*}}, align 1 | ||
| constexpr bool b11 = __builtin_sycl_is_kernel((void(*)(int *, int))ovl_free_func); // Okay | ||
| // CHECK: store i8 1, ptr addrspace(4) %b11{{.*}}, align 1 | ||
| } | ||
| 
     | 
||
| void f() { | ||
| auto L = []() { foo(); }; | ||
| q.submit([&](handler &h) { | ||
| h.single_task<class kernel_name_1>(L); | ||
| }); | ||
| } | 
      
      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.
Can you explain what passing the type to the
getTrue( )API does here? Is it possible to just return 0 or 1 if you are converting toConstantIntanyway?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 am not that familiar with this - but passing the type makes the function return a true value in the context of the type. There is another interface for getTrue, but it takes the LLVM context as its argument and returns a true value in that context. Passing the type made more sense and that is what other builtins seem to do too.
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.
Thank you for explaining