Skip to content

[SYCL] Add support for assuming SYCL queries fit in int #2215

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 11 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clang/include/clang/Basic/LangOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ LANGOPT(SYCLVersion , 32, 0, "Version of the SYCL standard used")
LANGOPT(DeclareSPIRVBuiltins, 1, 0, "Declare SPIR-V builtin functions")
LANGOPT(SYCLExplicitSIMD , 1, 0, "SYCL compilation with explicit SIMD extension")
LANGOPT(EnableDAEInSpirKernels , 1, 0, "Enable Dead Argument Elimination in SPIR kernels")
LANGOPT(
SYCLValueFitInMaxInt, 1, 0,
"SYCL compiler assumes value fits within MAX_INT for member function of "
"get/operator[], get_id/operator[] and get_global_id/get_global_linear_id "
"in SYCL class id, iterm and nd_iterm")

LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP")

Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,12 @@ def fsycl_device_code_split_EQ : Joined<["-"], "fsycl-device-code-split=">,
def fsycl_device_code_split : Flag<["-"], "fsycl-device-code-split">, Alias<fsycl_device_code_split_EQ>,
AliasArgs<["per_source"]>, Flags<[CC1Option, CoreOption]>,
HelpText<"Perform SYCL device code split in the per_source mode i.e. create a device code module for each source (translation unit)">;
def fsycl_id_queries_fit_in_int : Flag<["-"], "fsycl-id-queries-fit-in-int">,
Flags<[CC1Option, CoreOption]>, HelpText<"Assume that SYCL ID queries fit "
"within MAX_INT.">;
def fno_sycl_id_queries_fit_in_int : Flag<["-"], "fno-sycl-id-queries-fit-in-int">,
Flags<[CC1Option, CoreOption]>, HelpText<"Do not assume that SYCL ID queries "
"fit within MAX_INT.">;
def fsycl_use_bitcode : Flag<["-"], "fsycl-use-bitcode">,
Flags<[CC1Option, CoreOption]>, HelpText<"Use LLVM bitcode instead of SPIR-V in fat objects">;
def fno_sycl_use_bitcode : Flag<["-"], "fno-sycl-use-bitcode">,
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4147,6 +4147,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-Wno-sycl-strict");
}
}
if (IsSYCL || UseSYCLTriple) {
// Set options for both host and device
if (Arg *A = Args.getLastArg(options::OPT_fsycl_id_queries_fit_in_int,
options::OPT_fno_sycl_id_queries_fit_in_int))
A->render(Args, CmdArgs);
}

if (IsSYCL) {
if (SYCLStdArg) {
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,9 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
}
Opts.SYCLExplicitSIMD = Args.hasArg(options::OPT_fsycl_esimd);
Opts.EnableDAEInSpirKernels = Args.hasArg(options::OPT_fenable_sycl_dae);
Opts.SYCLValueFitInMaxInt =
Args.hasFlag(options::OPT_fsycl_id_queries_fit_in_int,
options::OPT_fno_sycl_id_queries_fit_in_int, false);
}

Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header);
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Frontend/InitPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
// SYCL Version is set to a value when building SYCL applications
if (LangOpts.SYCLVersion == 2017)
Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121");
if (LangOpts.SYCLValueFitInMaxInt)
Builder.defineMacro("__SYCL_ID_QUERIES_FIT_IN_INT__", "1");
}

if (LangOpts.DeclareSPIRVBuiltins) {
Expand Down
12 changes: 12 additions & 0 deletions clang/test/Driver/sycl.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,15 @@
// SYCL-HELP-FPGA: Use triple of 'spir64_fpga-unknown-unknown-sycldevice' to enable ahead of time compilation
// SYCL-HELP-CPU: Emitting help information for opencl-aot
// SYCL-HELP-CPU: Use triple of 'spir64_x86_64-unknown-unknown-sycldevice' to enable ahead of time compilation

// -fsycl-id-queries-fit-in-int
// RUN: %clang -### -fsycl -fsycl-id-queries-fit-in-int %s 2>&1 | FileCheck %s --check-prefix=ID_QUERIES
// RUN: %clang_cl -### -fsycl -fsycl-id-queries-fit-in-int %s 2>&1 | FileCheck %s --check-prefix=ID_QUERIES
// RUN: %clang -### -fsycl-device-only -fsycl-id-queries-fit-in-int %s 2>&1 | FileCheck %s --check-prefix=ID_QUERIES
// RUN: %clang_cl -### -fsycl-device-only -fsycl-id-queries-fit-in-int %s 2>&1 | FileCheck %s --check-prefix=ID_QUERIES
// RUN: %clang -### -fsycl -fno-sycl-id-queries-fit-in-int %s 2>&1 | FileCheck %s --check-prefix=NO_ID_QUERIES
// RUN: %clang_cl -### -fsycl -fno-sycl-id-queries-fit-in-int %s 2>&1 | FileCheck %s --check-prefix=NO_ID_QUERIES
// RUN: %clang -### -fsycl-device-only -fno-sycl-id-queries-fit-in-int %s 2>&1 | FileCheck %s --check-prefix=NO_ID_QUERIES
// RUN: %clang_cl -### -fsycl-device-only -fno-sycl-id-queries-fit-in-int %s 2>&1 | FileCheck %s --check-prefix=NO_ID_QUERIES
// ID_QUERIES: "-fsycl-id-queries-fit-in-int"
// NO_ID_QUERIES: "-fno-sycl-id-queries-fit-in-int"
19 changes: 13 additions & 6 deletions clang/test/Preprocessor/sycl-macro.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
// RUN: %clang_cc1 %s -E -dM | FileCheck %s
// RUN: %clang_cc1 %s -fsycl -fsycl-is-host -sycl-std=2017 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD %s
// RUN: %clang_cc1 %s -fsycl -fsycl-is-device -sycl-std=2017 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD %s
// RUN: %clang_cc1 %s -fsycl -fsycl-is-device -sycl-std=1.2.1 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD %s
// RUNx: %clang_cc1 %s -fsycl -fsycl-is-device -E -dM -fms-compatibility | FileCheck --check-prefix=CHECK-MSVC %s
// RUN: %clang_cc1 %s -fsycl -fsycl-id-queries-fit-in-int -fsycl-is-host -sycl-std=2017 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD %s
// RUN: %clang_cc1 %s -fsycl -fsycl-id-queries-fit-in-int -fsycl-is-device -sycl-std=2017 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD %s
// RUN: %clang_cc1 %s -fsycl -fsycl-id-queries-fit-in-int -fsycl-is-device -sycl-std=1.2.1 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD-DEVICE %s
// RUNx: %clang_cc1 %s -fsycl -fsycl-id-queries-fit-in-int -fsycl-is-device -E -dM -fms-compatibility | FileCheck --check-prefix=CHECK-MSVC %s
// RUN: %clang_cc1 -fno-sycl-id-queries-fit-in-int %s -E -dM | FileCheck \
// RUN: --check-prefix=CHECK-NO-SYCL_FIT_IN_INT %s

// CHECK-NOT:#define __SYCL_DEVICE_ONLY__ 1
// CHECK-NOT:#define SYCL_EXTERNAL
// CHECK-NOT:#define CL_SYCL_LANGUAGE_VERSION 121
// CHECK-NOT:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1

// CHECK-SYCL-STD:#define CL_SYCL_LANGUAGE_VERSION 121
// CHECK-SYCL-STD:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1

// CHECK-SYCL:#define __SYCL_DEVICE_ONLY__ 1
// CHECK-SYCL:#define SYCL_EXTERNAL __attribute__((sycl_device))
// CHECK-SYCL-STD-DEVICE:#define __SYCL_DEVICE_ONLY__ 1
// CHECK-SYCL-STD-DEVICE:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1

// CHECK-MSVC-NOT: __GNUC__
// CHECK-MSVC-NOT: __STDC__
// CHECK-MSVC: #define __SYCL_ID_QUERIES_FIT_IN_INT__ 1

// CHECK-NO-SYCL_FIT_IN_INT-NOT:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1
14 changes: 6 additions & 8 deletions sycl/include/CL/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,16 @@ __SYCL_EXPORT device getDeviceFromHandler(handler &);
#if defined(__SYCL_ID_QUERIES_FIT_IN_INT__)
template <typename T> struct NotIntMsg;

// TODO reword for "`fsycl-id-queries-fit-in-int' optimization flag." when
// implemented
template <int Dims> struct NotIntMsg<range<Dims>> {
constexpr static char *Msg = "Provided range is out of integer limits. "
"Pass `-U__SYCL_ID_QUERIES_FIT_IN_INT__' to "
"disable range check.";
constexpr static const char *Msg =
"Provided range is out of integer limits. Pass "
"`-fno-sycl-id-queries-fit-in-int' to disable range check.";
};

template <int Dims> struct NotIntMsg<id<Dims>> {
constexpr static char *Msg = "Provided offset is out of integer limits. "
"Pass `-U__SYCL_ID_QUERIES_FIT_IN_INT__' to "
"disable offset check.";
constexpr static const char *Msg =
"Provided offset is out of integer limits. Pass "
"`-fno-sycl-id-queries-fit-in-int' to disable offset check.";
};
#endif

Expand Down
6 changes: 3 additions & 3 deletions sycl/test/basic_tests/range_offset_fit_in_int.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -D__SYCL_ID_QUERIES_FIT_IN_INT__=1 %s -o %t.out
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -fsycl-id-queries-fit-in-int %s -o %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out

#include <CL/sycl.hpp>
Expand All @@ -8,7 +8,7 @@ namespace S = cl::sycl;

void checkRangeException(S::runtime_error &E) {
constexpr char Msg[] = "Provided range is out of integer limits. "
"Pass `-U__SYCL_ID_QUERIES_FIT_IN_INT__' to "
"Pass `-fno-sycl-id-queries-fit-in-int' to "
"disable range check.";

std::cerr << E.what() << std::endl;
Expand All @@ -18,7 +18,7 @@ void checkRangeException(S::runtime_error &E) {

void checkOffsetException(S::runtime_error &E) {
constexpr char Msg[] = "Provided offset is out of integer limits. "
"Pass `-U__SYCL_ID_QUERIES_FIT_IN_INT__' to "
"Pass `-fno-sycl-id-queries-fit-in-int' to "
"disable offset check.";

std::cerr << E.what() << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion sycl/test/check_device_code/id_queries_fit_int.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clangxx -fsycl -Xclang -fsycl-is-host -O1 -c -S -emit-llvm -o %t.ll -D__SYCL_ID_QUERIES_FIT_IN_INT__=1 %s
// RUN: %clangxx -fsycl -Xclang -fsycl-is-host -fsycl-id-queries-fit-in-int -O1 -c -S -emit-llvm -o %t.ll %s
// RUN: FileCheck %s --input-file %t.ll

#include <CL/sycl.hpp>
Expand Down