Skip to content

Commit de6dc89

Browse files
committed
Merge from 'sycl' to 'sycl-web' (#2)
CONFLICT (content): Merge conflict in sycl/plugins/opencl/pi_opencl.cpp
2 parents 4e3645d + 7a7f47d commit de6dc89

File tree

12 files changed

+126
-31
lines changed

12 files changed

+126
-31
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5527,9 +5527,11 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
55275527
if ((!AtTopLevel && !isSaveTempsEnabled() &&
55285528
(!C.getArgs().hasArg(options::OPT__SLASH_Fo) ||
55295529
// FIXME - The use of /Fo is limited when offloading is enabled. When
5530-
// compiling to exe use of /Fo does not produce the named obj
5530+
// compiling to exe use of /Fo does not produce the named obj. We also
5531+
// should not use the named output when performing unbundling.
55315532
(C.getArgs().hasArg(options::OPT__SLASH_Fo) &&
55325533
(!JA.isOffloading(Action::OFK_None) ||
5534+
isa<OffloadUnbundlingJobAction>(JA) ||
55335535
JA.getOffloadingHostActiveKinds() > Action::OFK_Host)))) ||
55345536
CCGenDiagnostics) {
55355537
StringRef Name = llvm::sys::path::filename(BaseInput);
@@ -5567,7 +5569,8 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
55675569
// Determine what the derived output name should be.
55685570
const char *NamedOutput;
55695571

5570-
if ((JA.getType() == types::TY_Object || JA.getType() == types::TY_LTO_BC) &&
5572+
if ((JA.getType() == types::TY_Object || JA.getType() == types::TY_LTO_BC ||
5573+
JA.getType() == types::TY_Archive) &&
55715574
C.getArgs().hasArg(options::OPT__SLASH_Fo, options::OPT__SLASH_o)) {
55725575
// The /Fo or /o flag decides the object filename.
55735576
StringRef Val =

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,8 @@ void Sema::ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc,
12851285
FunctionDecl *OpenCLKernel =
12861286
CreateOpenCLKernelDeclaration(getASTContext(), Name, ParamDescs);
12871287

1288+
ContextRAII FuncContext(*this, OpenCLKernel);
1289+
12881290
// Let's copy source location of a functor/lambda to emit nicer diagnostics
12891291
OpenCLKernel->setLocation(LE->getLocation());
12901292

clang/test/Driver/sycl-offload-intelfpga.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,44 @@
1616

1717
/// -fintelfpga -fsycl-link tests
1818
// RUN: touch %t.o
19-
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -fsycl-link %t.o 2>&1 \
19+
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -fsycl-link %t.o -o libfoo.a 2>&1 \
2020
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK,CHK-FPGA-EARLY %s
21-
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -fsycl-link=early %t.o 2>&1 \
21+
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -fsycl-link=early %t.o -o libfoo.a 2>&1 \
2222
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK,CHK-FPGA-EARLY %s
23-
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -fsycl-link=image %t.o 2>&1 \
23+
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -fsycl-link=image %t.o -o libfoo.a 2>&1 \
2424
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK,CHK-FPGA-IMAGE %s
2525
// CHK-FPGA-LINK-NOT: clang-offload-bundler{{.*}} "-check-section"
2626
// CHK-FPGA-LINK: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64_fpga-unknown-unknown-sycldevice" "-inputs=[[INPUT:.+\.o]]" "-outputs=[[OUTPUT1:.+\.o]]" "-unbundle"
27+
// CHK-FPGA-LINK-NOT: clang-offload-bundler{{.*}}
2728
// CHK-FPGA-LINK: llvm-link{{.*}} "[[OUTPUT1]]" "-o" "[[OUTPUT2:.+\.bc]]"
2829
// CHK-FPGA-LINK: llvm-spirv{{.*}} "-o" "[[OUTPUT3:.+\.spv]]" "-spirv-max-version=1.1" "-spirv-ext=+all" "[[OUTPUT2]]"
2930
// CHK-FPGA-EARLY: aoc{{.*}} "-o" "[[OUTPUT4:.+\.aocr]]" "[[OUTPUT3]]" "-sycl" "-rtl"
3031
// CHK-FPGA-IMAGE: aoc{{.*}} "-o" "[[OUTPUT5:.+\.aocx]]" "[[OUTPUT3]]" "-sycl"
31-
// CHK-FPGA-LINK: {{lib|llvm-ar}}{{.*}} "[[INPUT]]"
32+
// CHK-FPGA-LINK: llvm-ar{{.*}} "cr" "libfoo.a" "[[INPUT]]"
33+
34+
// Output designation should not be used for unbundling step
35+
// RUN: touch %t.o
36+
// RUN: touch %t.obj
37+
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -fsycl-link %t.o -o libfoo.a 2>&1 \
38+
// RUN: | FileCheck -check-prefix=CHK-FPGA-LINK-OUT %s
39+
// RUN: %clang_cl -### -fsycl -fintelfpga -fsycl-link %t.obj -Folibfoo.a 2>&1 \
40+
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK-OUT %s
41+
// RUN: %clang_cl -### -fsycl -fintelfpga -fsycl-link %t.obj -o libfoo.a 2>&1 \
42+
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK-OUT %s
43+
// CHK-FPGA-LINK-OUT-NOT: clang-offload-bundler{{.*}} "-outputs=libfoo.a" "-unbundle"
3244

3345
/// -fintelfpga -fsycl-link clang-cl specific
3446
// RUN: touch %t.obj
35-
// RUN: %clang_cl -### -fsycl -fintelfpga -fsycl-link %t.obj 2>&1 \
47+
// RUN: %clang_cl -### -fsycl -fintelfpga -fsycl-link %t.obj -Folibfoo.lib 2>&1 \
48+
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK-WIN %s
49+
// RUN: %clang_cl -### -fsycl -fintelfpga -fsycl-link %t.obj -o libfoo.lib 2>&1 \
3650
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK-WIN %s
3751
// CHK-FPGA-LINK-WIN: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64_fpga-unknown-unknown-sycldevice{{.*}}" "-inputs=[[INPUT:.+\.obj]]" "-outputs=[[OUTPUT1:.+\.obj]]" "-unbundle"
52+
// CHK-FPGA-LINK-WIN-NOT: clang-offload-bundler{{.*}}
3853
// CHK-FPGA-LINK-WIN: llvm-link{{.*}} "[[OUTPUT1]]" "-o" "[[OUTPUT2:.+\.bc]]"
3954
// CHK-FPGA-LINK-WIN: llvm-spirv{{.*}} "-o" "[[OUTPUT3:.+\.spv]]" "-spirv-max-version=1.1" "-spirv-ext=+all" "[[OUTPUT2]]"
4055
// CHK-FPGA-LINK-WIN: aoc{{.*}} "-o" "[[OUTPUT5:.+\.aocr]]" "[[OUTPUT3]]" "-sycl" "-rtl"
41-
// CHK-FPGA-LINK-WIN: lib.exe{{.*}} "[[INPUT]]"
42-
56+
// CHK-FPGA-LINK-WIN: lib.exe{{.*}} "[[INPUT]]" {{.*}} "-OUT:libfoo.lib"
4357

4458
/// Check -fintelfpga -fsycl-link with an FPGA archive
4559
// Create the dummy archive

sycl/include/CL/sycl/detail/sycl_mem_obj_t.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,14 @@ template <typename AllocatorT> class SYCLMemObjT : public SYCLMemObjI {
165165

166166
template <typename Destination>
167167
EnableIfOutputPointerT<Destination> set_final_data(Destination FinalData) {
168-
MUploadDataFunctor = [this, FinalData]() {
169-
EventImplPtr Event = updateHostMemory(FinalData);
170-
if (Event)
171-
Event->wait(Event);
172-
};
168+
if (!FinalData)
169+
MUploadDataFunctor = nullptr;
170+
else
171+
MUploadDataFunctor = [this, FinalData]() {
172+
EventImplPtr Event = updateHostMemory(FinalData);
173+
if (Event)
174+
Event->wait(Event);
175+
};
173176
}
174177

175178
template <typename Destination>

sycl/plugins/opencl/pi_opencl.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,28 @@ template <class To, class From> To cast(From value) {
3030
return (To)(value);
3131
}
3232

33+
// Older versions of GCC don't like "const" here
34+
#if defined(__GNUC__) && (__GNUC__ < 7 || (__GNU__C == 7 && __GNUC_MINOR__ < 2))
35+
#define CONSTFIX constexpr
36+
#else
37+
#define CONSTFIX const
38+
#endif
39+
3340
// Names of USM functions that are queried from OpenCL
34-
constexpr char clHostMemAllocName[] = "clHostMemAllocINTEL";
35-
constexpr char clDeviceMemAllocName[] = "clDeviceMemAllocINTEL";
36-
constexpr char clSharedMemAllocName[] = "clSharedMemAllocINTEL";
37-
constexpr char clMemFreeName[] = "clMemFreeINTEL";
38-
constexpr char clSetKernelArgMemPointerName[] = "clSetKernelArgMemPointerINTEL";
39-
constexpr char clEnqueueMemsetName[] = "clEnqueueMemsetINTEL";
40-
constexpr char clEnqueueMemcpyName[] = "clEnqueueMemcpyINTEL";
41-
constexpr char clEnqueueMigrateMemName[] = "clEnqueueMigrateMemINTEL";
42-
constexpr char clEnqueueMemAdviseName[] = "clEnqueueMemAdviseINTEL";
43-
constexpr char clGetMemAllocInfoName[] = "clGetMemAllocInfoINTEL";
41+
CONSTFIX char clHostMemAllocName[] = "clHostMemAllocINTEL";
42+
CONSTFIX char clDeviceMemAllocName[] = "clDeviceMemAllocINTEL";
43+
CONSTFIX char clSharedMemAllocName[] = "clSharedMemAllocINTEL";
44+
CONSTFIX char clMemFreeName[] = "clMemFreeINTEL";
45+
CONSTFIX char clSetKernelArgMemPointerName[] = "clSetKernelArgMemPointerINTEL";
46+
CONSTFIX char clEnqueueMemsetName[] = "clEnqueueMemsetINTEL";
47+
CONSTFIX char clEnqueueMemcpyName[] = "clEnqueueMemcpyINTEL";
48+
CONSTFIX char clEnqueueMigrateMemName[] = "clEnqueueMigrateMemINTEL";
49+
CONSTFIX char clEnqueueMemAdviseName[] = "clEnqueueMemAdviseINTEL";
50+
CONSTFIX char clGetMemAllocInfoName[] = "clGetMemAllocInfoINTEL";
51+
52+
#undef CONSTFIX
53+
54+
4455

4556
// USM helper function to get an extension function pointer
4657
template <const char *FuncName, typename T>

sycl/source/detail/scheduler/graph_builder.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,31 @@ Command *Scheduler::GraphBuilder::insertMemoryMove(MemObjRecord *Record,
232232

233233
AllocaCommandBase *AllocaCmdSrc =
234234
findAllocaForReq(Record, Req, Record->MCurContext);
235+
if (!AllocaCmdSrc && IsSuitableSubReq(Req)) {
236+
// Since no alloca command for the sub buffer requirement was found in the
237+
// current context, need to find a parent alloca command for it (it must be
238+
// there)
239+
auto IsSuitableAlloca = [Record, Req](AllocaCommandBase *AllocaCmd) {
240+
bool Res = sameCtx(AllocaCmd->getQueue()->get_context_impl(),
241+
Record->MCurContext) &&
242+
// Looking for a parent buffer alloca command
243+
AllocaCmd->getType() == Command::CommandType::ALLOCA;
244+
return Res;
245+
};
246+
const auto It =
247+
std::find_if(Record->MAllocaCommands.begin(),
248+
Record->MAllocaCommands.end(), IsSuitableAlloca);
249+
AllocaCmdSrc = (Record->MAllocaCommands.end() != It) ? *It : nullptr;
250+
}
235251
if (!AllocaCmdSrc)
236252
throw runtime_error("Cannot find buffer allocation");
237253
// Get parent allocation of sub buffer to perform full copy of whole buffer
238254
if (IsSuitableSubReq(Req)) {
239255
if (AllocaCmdSrc->getType() == Command::CommandType::ALLOCA_SUB_BUF)
240256
AllocaCmdSrc =
241257
static_cast<AllocaSubBufCommand *>(AllocaCmdSrc)->getParentAlloca();
242-
else
243-
assert(
244-
!"Inappropriate alloca command. AllocaSubBufCommand was expected.");
258+
else if (AllocaCmdSrc->getSYCLMemObj() != Req->MSYCLMemObj)
259+
assert(!"Inappropriate alloca command.");
245260
}
246261

247262
Command *NewCmd = nullptr;

sycl/test/basic_tests/buffer/subbuffer.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,37 @@ void copyBlock() {
247247
}
248248
}
249249

250+
void checkMultipleContexts() {
251+
constexpr int N = 64;
252+
int a[N] = {0};
253+
{
254+
sycl::queue queue1;
255+
sycl::queue queue2;
256+
sycl::buffer<int, 1> buf(a, sycl::range<1>(N));
257+
sycl::buffer<int, 1> subbuf1(buf, sycl::id<1>(0), sycl::range<1>(N / 2));
258+
sycl::buffer<int, 1> subbuf2(buf, sycl::id<1>(N / 2),
259+
sycl::range<1>(N / 2));
260+
queue1.submit([&](sycl::handler &cgh) {
261+
auto bufacc = subbuf1.get_access<sycl::access::mode::read_write>(cgh);
262+
cgh.parallel_for<class sub_buffer_1>(
263+
sycl::range<1>(N / 2), [=](sycl::id<1> idx) { bufacc[idx[0]] = 1; });
264+
});
265+
266+
queue2.submit([&](sycl::handler &cgh) {
267+
auto bufacc = subbuf2.get_access<sycl::access::mode::read_write>(cgh);
268+
cgh.parallel_for<class sub_buffer_2>(
269+
sycl::range<1>(N / 2), [=](sycl::id<1> idx) { bufacc[idx[0]] = 2; });
270+
});
271+
}
272+
assert(a[N / 2 - 1] == 1 && a[N / 2] == 2 && "Sub buffer data loss");
273+
}
274+
250275
int main() {
251276
cl::sycl::queue q;
252277
check1DSubBuffer(q);
253278
checkHostAccessor(q);
254279
checkExceptions();
255280
copyBlock();
281+
checkMultipleContexts();
256282
return 0;
257283
}

sycl/test/basic_tests/image.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,31 @@ int main() {
7373
});
7474
}
7575

76+
// image with write accessor to it in kernel
77+
{
78+
int NX = 32;
79+
int NY = 32;
80+
81+
sycl::image<2> Img(sycl::image_channel_order::rgba,
82+
sycl::image_channel_type::fp32,
83+
sycl::range<2>(NX, NY));
84+
85+
sycl::queue Q;
86+
Q.submit([&](sycl::handler &CGH) {
87+
auto ImgAcc = Img.get_access<sycl::float4, sycl::access::mode::write>(
88+
CGH);
89+
90+
sycl::nd_range<2> Rng(sycl::range<2>(NX, NY), sycl::range<2>(16, 16));
91+
92+
CGH.parallel_for<class sample>(Rng, [=](sycl::nd_item<2> Item) {
93+
sycl::id<2> Idx = Item.get_global_id();
94+
sycl::float4 C(0.5f, 0.5f, 0.2f, 1.0f);
95+
ImgAcc.write(sycl::int2(Idx[0], Idx[1]), C);
96+
});
97+
98+
}).wait_and_throw();
99+
}
100+
76101
std::cout << "Success" << std::endl;
77102
return 0;
78103
}

sycl/test/basic_tests/stream/auto_flush.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// RUN: %CPU_RUN_PLACEHOLDER %t.out %CPU_CHECK_PLACEHOLDER
44
// RUN: %GPU_RUN_ON_LINUX_PLACEHOLDER %t.out %GPU_CHECK_ON_LINUX_PLACEHOLDER
55
// RUN: %ACC_RUN_PLACEHOLDER %t.out %ACC_CHECK_PLACEHOLDER
6-
// TODO: SYCL specific fail - analyze and enable
76
//==-------------- copy.cpp - SYCL stream obect auto flushing test ---------==//
87
//
98
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.

sycl/test/basic_tests/stream/stream.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// RUN: %CPU_RUN_PLACEHOLDER %t.out %CPU_CHECK_PLACEHOLDER
44
// RUN: %GPU_RUN_ON_LINUX_PLACEHOLDER %t.out %GPU_CHECK_ON_LINUX_PLACEHOLDER
55
// RUN: %ACC_RUN_PLACEHOLDER %t.out %ACC_CHECK_PLACEHOLDER
6-
// TODO: SYCL specific fail - analyze and enable
76
//==------------------ stream.cpp - SYCL stream basic test -----------------==//
87
//
98
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.

sycl/test/hier_par/hier_par_basic.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
// RUN: %clangxx -fsycl %s -o %t.out
1010
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
11-
// TODO: SYCL specific fail - analyze and enable on Windows
1211
// RUN: %CPU_RUN_PLACEHOLDER %t.out
1312
// RUN: %GPU_RUN_PLACEHOLDER %t.out
1413
// RUN: %ACC_RUN_PLACEHOLDER %t.out

sycl/test/hier_par/hier_par_wgscope.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
// RUN: %clangxx -fsycl %s -o %t.out
1010
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
11-
// TODO: SYCL specific fail - analyze and enable on Windows
1211
// RUN: %CPU_RUN_PLACEHOLDER %t.out
1312
// RUN: %GPU_RUN_PLACEHOLDER %t.out
1413
// RUN: %ACC_RUN_PLACEHOLDER %t.out

0 commit comments

Comments
 (0)