Skip to content

Commit

Permalink
[OpenCL] Align subgroup builtin guards
Browse files Browse the repository at this point in the history
Until now, subgroup builtins are available with `opencl-c.h` when at
least one of `cl_intel_subgroups`, `cl_khr_subgroups`, or
`__opencl_c_subgroups` is defined.  With `-fdeclare-opencl-builtins`,
subgroup builtins are conditionalized on `cl_khr_subgroups` only.

Align `-fdeclare-opencl-builtins` to `opencl-c.h` by introducing the
internal `__opencl_subgroup_builtins` macro.

Differential Revision: https://reviews.llvm.org/D120254
  • Loading branch information
svenvh committed Feb 23, 2022
1 parent 5fb6555 commit aa9c2d1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions clang/lib/Headers/opencl-c-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
#define __opencl_c_named_address_space_builtins 1
#endif // !defined(__opencl_c_generic_address_space)

#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups) || defined(__opencl_c_subgroups)
// Internal feature macro to provide subgroup builtins.
#define __opencl_subgroup_builtins 1
#endif

// built-in scalar data types:

/**
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Headers/opencl-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -16282,7 +16282,7 @@ queue_t __ovld get_default_queue(void);

// OpenCL Extension v2.0 s9.17 - Sub-groups

#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups) || defined(__opencl_c_subgroups)
#if defined(__opencl_subgroup_builtins)
// Shared Sub Group Functions
uint __ovld get_sub_group_size(void);
uint __ovld get_max_sub_group_size(void);
Expand Down Expand Up @@ -16381,7 +16381,7 @@ double __ovld __conv sub_group_scan_inclusive_min(double x);
double __ovld __conv sub_group_scan_inclusive_max(double x);
#endif //cl_khr_fp64

#endif //cl_khr_subgroups cl_intel_subgroups __opencl_c_subgroups
#endif // __opencl_subgroup_builtins

#if defined(cl_khr_subgroup_extended_types)
char __ovld __conv sub_group_broadcast( char value, uint index );
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/OpenCLBuiltins.td
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def AtomicFp64TypeExt : TypeExtension<"cl_khr_int64_base_atomics cl_khr_int64_ex

// FunctionExtension definitions.
def FuncExtNone : FunctionExtension<"">;
def FuncExtKhrSubgroups : FunctionExtension<"cl_khr_subgroups">;
def FuncExtKhrSubgroups : FunctionExtension<"__opencl_subgroup_builtins">;
def FuncExtKhrSubgroupExtendedTypes : FunctionExtension<"cl_khr_subgroup_extended_types">;
def FuncExtKhrSubgroupNonUniformVote : FunctionExtension<"cl_khr_subgroup_non_uniform_vote">;
def FuncExtKhrSubgroupBallot : FunctionExtension<"cl_khr_subgroup_ballot">;
Expand Down
5 changes: 3 additions & 2 deletions clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -DNO_HEADER
// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -finclude-default-header
// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER
// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER -cl-ext=-cl_intel_subgroups
// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header -cl-ext=-cl_intel_subgroups
// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL3.0 -fdeclare-opencl-builtins -finclude-default-header
Expand Down Expand Up @@ -79,6 +79,7 @@ typedef struct {int a;} ndrange_t;
#define cl_khr_subgroup_non_uniform_arithmetic 1
#define cl_khr_subgroup_clustered_reduce 1
#define __opencl_c_read_write_images 1
#define __opencl_subgroup_builtins 1
#endif

#if (__OPENCL_CPP_VERSION__ == 100 || __OPENCL_C_VERSION__ == 200)
Expand Down

0 comments on commit aa9c2d1

Please sign in to comment.