Skip to content

Commit a887b70

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web'
2 parents 1f60bbe + e86baf4 commit a887b70

File tree

13 files changed

+132
-301
lines changed

13 files changed

+132
-301
lines changed

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,10 +2059,9 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
20592059
llvm::Type *SrcTy = Src->getType();
20602060
llvm::Type *DstTy = ConvertType(DestTy);
20612061
if (SrcTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() &&
2062-
SrcTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace()) {
2063-
llvm_unreachable("wrong cast for pointers in different address spaces"
2064-
"(must be an address space cast)!");
2065-
}
2062+
SrcTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace())
2063+
Src = Builder.CreateAddrSpaceCast(
2064+
Src, llvm::PointerType::get(SrcTy, DstTy->getPointerAddressSpace()));
20662065

20672066
if (CGF.SanOpts.has(SanitizerKind::CFIUnrelatedCast)) {
20682067
if (auto *PT = DestTy->getAs<PointerType>()) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 -triple spir64-unknown-linux -fsycl-is-device -disable-llvm-passes -emit-llvm -x c++ %s -o - | FileCheck %s
2+
3+
// Test to verify that address space cast is generated correctly for __builtin_alloca
4+
5+
__attribute__((sycl_device)) void foo() {
6+
// CHECK: %TestVar = alloca i32 addrspace(4)*, align 8
7+
// CHECK: %TestVar.ascast = addrspacecast i32 addrspace(4)** %TestVar to i32 addrspace(4)* addrspace(4)*
8+
// CHECK: %[[ALLOCA:[0-9]+]] = alloca i8, i64 1, align 8
9+
// CHECK: %[[ADDRSPCAST:[0-9]+]] = addrspacecast i8* %[[ALLOCA]] to i8* addrspace(4)*
10+
// CHECK: %[[BITCAST:[0-9]+]] = bitcast i8* addrspace(4)* %[[ADDRSPCAST]] to i32 addrspace(4)*
11+
// CHECK: store i32 addrspace(4)* %[[BITCAST]], i32 addrspace(4)* addrspace(4)* %TestVar.ascast, align 8
12+
int *TestVar = (int *)__builtin_alloca(1);
13+
}

libdevice/cmake/modules/SYCLLibdevice.cmake

Lines changed: 71 additions & 251 deletions
Large diffs are not rendered by default.

libdevice/cmath_wrapper_fp64.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//==--- cmath_wrapper.cpp - wrappers for C math library functions ----------==//
1+
//==--- cmath_wrapper_fp64.cpp - wrappers for double precision C math library
2+
// functions ----------==//
23
//
34
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45
// See https://llvm.org/LICENSE.txt for license information.

libdevice/complex_wrapper_fp64.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//==--- complex_wrapper.cpp - wrappers for C99 complex math functions ------==//
1+
//==--- complex_wrapper_fp64.cpp - wrappers for double precision C99 complex
2+
// math functions ------==//
23
//
34
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45
// See https://llvm.org/LICENSE.txt for license information.

libdevice/fallback-cmath-fp64.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//==--- fallback-cmath.cpp - fallback implementation of math functions -----==//
1+
//==--- fallback-cmath-fp64.cpp - fallback implementation of double precision
2+
// math functions -----==//
23
//
34
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45
// See https://llvm.org/LICENSE.txt for license information.

libdevice/fallback-complex-fp64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//==----- fallback-complex.cpp - complex math functions for SPIR-V device --==//
1+
//==----- fallback-complex-fp64.cpp - double precision complex math functions
2+
// for SPIR-V device --==//
23
//
34
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45
// See https://llvm.org/LICENSE.txt for license information.
@@ -7,7 +8,6 @@
78
//===----------------------------------------------------------------------===//
89

910
#include "device_complex.h"
10-
#include "device_math.h"
1111

1212
#ifdef __SPIR__
1313
#include <cmath>

libdevice/fallback-complex.cpp

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

99
#include "device_complex.h"
10-
#include "device_math.h"
1110

1211
#ifdef __SPIR__
1312
#include <cmath>

sycl/plugins/level_zero/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ if (SYCL_ENABLE_XPTI_TRACING)
103103
set(XPTI_PROXY_SRC "${CMAKE_SOURCE_DIR}/../xpti/src/xpti_proxy.cpp")
104104
endif()
105105

106+
find_package(Threads REQUIRED)
107+
106108
add_sycl_plugin(level_zero
107109
SOURCES
108110
"${sycl_inc_dir}/CL/sycl/detail/pi.h"

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4636,18 +4636,31 @@ pi_result piKernelCreate(pi_program Program, const char *KernelName,
46364636
return PI_ERROR_UNKNOWN;
46374637
}
46384638

4639-
// Update the refcount of the program and context to show it's used by this
4640-
// kernel.
4639+
PI_CALL((*RetKernel)->initialize());
4640+
return PI_SUCCESS;
4641+
}
4642+
4643+
pi_result _pi_kernel::initialize() {
4644+
// Retain the program and context to show it's used by this kernel.
46414645
PI_CALL(piProgramRetain(Program));
46424646
if (IndirectAccessTrackingEnabled)
46434647
// TODO: do piContextRetain without the guard
46444648
PI_CALL(piContextRetain(Program->Context));
46454649

46464650
// Set up how to obtain kernel properties when needed.
4647-
(*RetKernel)->ZeKernelProperties.Compute =
4648-
[ZeKernel](ze_kernel_properties_t &Properties) {
4649-
ZE_CALL_NOCHECK(zeKernelGetProperties, (ZeKernel, &Properties));
4650-
};
4651+
ZeKernelProperties.Compute = [this](ze_kernel_properties_t &Properties) {
4652+
ZE_CALL_NOCHECK(zeKernelGetProperties, (ZeKernel, &Properties));
4653+
};
4654+
4655+
// Cache kernel name.
4656+
ZeKernelName.Compute = [this](std::string &Name) {
4657+
size_t Size = 0;
4658+
ZE_CALL_NOCHECK(zeKernelGetName, (ZeKernel, &Size, nullptr));
4659+
char *KernelName = new char[Size];
4660+
ZE_CALL_NOCHECK(zeKernelGetName, (ZeKernel, &Size, KernelName));
4661+
Name = KernelName;
4662+
delete[] KernelName;
4663+
};
46514664

46524665
return PI_SUCCESS;
46534666
}
@@ -4727,13 +4740,8 @@ pi_result piKernelGetInfo(pi_kernel Kernel, pi_kernel_info ParamName,
47274740
return ReturnValue(pi_program{Kernel->Program});
47284741
case PI_KERNEL_INFO_FUNCTION_NAME:
47294742
try {
4730-
size_t Size = 0;
4731-
ZE_CALL(zeKernelGetName, (Kernel->ZeKernel, &Size, nullptr));
4732-
char *KernelName = new char[Size];
4733-
ZE_CALL(zeKernelGetName, (Kernel->ZeKernel, &Size, KernelName));
4734-
pi_result Res = ReturnValue(static_cast<const char *>(KernelName));
4735-
delete[] KernelName;
4736-
return Res;
4743+
std::string &KernelName = *Kernel->ZeKernelName.operator->();
4744+
return ReturnValue(static_cast<const char *>(KernelName.c_str()));
47374745
} catch (const std::bad_alloc &) {
47384746
return PI_OUT_OF_HOST_MEMORY;
47394747
} catch (...) {
@@ -5086,20 +5094,7 @@ pi_result piextKernelCreateWithNativeHandle(pi_native_handle NativeHandle,
50865094

50875095
auto ZeKernel = pi_cast<ze_kernel_handle_t>(NativeHandle);
50885096
*Kernel = new _pi_kernel(ZeKernel, OwnNativeHandle, Program);
5089-
5090-
// Update the refcount of the program and context to show it's used by this
5091-
// kernel.
5092-
PI_CALL(piProgramRetain(Program));
5093-
if (IndirectAccessTrackingEnabled)
5094-
// TODO: do piContextRetain without the guard
5095-
PI_CALL(piContextRetain(Program->Context));
5096-
5097-
// Set up how to obtain kernel properties when needed.
5098-
(*Kernel)->ZeKernelProperties.Compute =
5099-
[ZeKernel](ze_kernel_properties_t &Properties) {
5100-
ZE_CALL_NOCHECK(zeKernelGetProperties, (ZeKernel, &Properties));
5101-
};
5102-
5097+
PI_CALL((*Kernel)->initialize());
51035098
return PI_SUCCESS;
51045099
}
51055100

0 commit comments

Comments
 (0)