Skip to content

Commit

Permalink
Merge branch 'sycl' into steffen/move_handler_elems
Browse files Browse the repository at this point in the history
  • Loading branch information
steffenlarsen authored Jul 12, 2024
2 parents 1a4f3a3 + a9b2ead commit affd0ba
Show file tree
Hide file tree
Showing 110 changed files with 826 additions and 2,224 deletions.
5 changes: 0 additions & 5 deletions clang/lib/CodeGen/CodeGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,6 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
"__spv::__spirv_CooperativeMatrixKHR") {
ResultType = ConvertSPVCooperativeMatrixType(RD);
break;
} else if (RD && RD->getQualifiedNameAsString() ==
"__spv::__spirv_TaskSequenceINTEL") {
ResultType = llvm::TargetExtType::get(getLLVMContext(),
"spirv.TaskSequenceINTEL");
break;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10553,7 +10553,6 @@ static void getTripleBasedSPIRVTransOpts(Compilation &C,
",+SPV_INTEL_fpga_argument_interfaces"
",+SPV_INTEL_fpga_invocation_pipelining_attributes"
",+SPV_INTEL_fpga_latency_control"
",+SPV_INTEL_task_sequence"
",+SPV_KHR_shader_clock"
",+SPV_INTEL_bindless_images";
ExtArg = ExtArg + DefaultExtArg + INTELExtArg;
Expand Down
9 changes: 9 additions & 0 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,15 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple,
getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
<< "-device" << Target;
}
// ocloc has different names for some of the newer architectures;
// translate them to the apropriate value here.
DepInfo =
llvm::StringSwitch<StringRef>(DepInfo)
.Cases("pvc_vg", "12_61_7", "pvc_xt_c0_vg")
.Cases("mtl_u", "mtl_s", "arl_u", "arl_s", "12_70_4", "mtl_s")
.Cases("mtl_h", "12_71_4", "mtl_p")
.Cases("arl_h", "12_74_4", "xe_lpgplus_b0")
.Default(DepInfo);
CmdArgs.push_back("-device");
CmdArgs.push_back(Args.MakeArgString(DepInfo));
}
Expand Down
11 changes: 0 additions & 11 deletions clang/test/CodeGenSYCL/intel-task-sequence.cpp

This file was deleted.

22 changes: 11 additions & 11 deletions clang/test/Driver/sycl-oneapi-gpu-intelgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,27 @@
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_12_60_7 -### %s 2>&1 | \
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=pvc -DMAC_STR=PVC
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_pvc_vg -### %s 2>&1 | \
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=pvc_vg -DMAC_STR=PVC_VG
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=pvc_xt_c0_vg -DMAC_STR=PVC_VG
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_12_61_7 -### %s 2>&1 | \
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=pvc_vg -DMAC_STR=PVC_VG
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=pvc_xt_c0_vg -DMAC_STR=PVC_VG
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_mtl_u -### %s 2>&1 | \
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=mtl_u -DMAC_STR=MTL_U
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=mtl_s -DMAC_STR=MTL_U
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_mtl_s -### %s 2>&1 | \
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=mtl_u -DMAC_STR=MTL_U
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=mtl_s -DMAC_STR=MTL_U
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_arl_u -### %s 2>&1 | \
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=mtl_u -DMAC_STR=MTL_U
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=mtl_s -DMAC_STR=MTL_U
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_arl_s -### %s 2>&1 | \
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=mtl_u -DMAC_STR=MTL_U
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=mtl_s -DMAC_STR=MTL_U
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_12_70_4 -### %s 2>&1 | \
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=mtl_u -DMAC_STR=MTL_U
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=mtl_s -DMAC_STR=MTL_U
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_mtl_h -### %s 2>&1 | \
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=mtl_h -DMAC_STR=MTL_H
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=mtl_p -DMAC_STR=MTL_H
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_12_71_4 -### %s 2>&1 | \
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=mtl_h -DMAC_STR=MTL_H
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=mtl_p -DMAC_STR=MTL_H
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_arl_h -### %s 2>&1 | \
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=arl_h -DMAC_STR=ARL_H
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=xe_lpgplus_b0 -DMAC_STR=ARL_H
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_12_74_4 -### %s 2>&1 | \
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=arl_h -DMAC_STR=ARL_H
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=xe_lpgplus_b0 -DMAC_STR=ARL_H
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_bmg_g21 -### %s 2>&1 | \
// RUN: FileCheck %s --check-prefixes=DEVICE,MACRO -DDEV_STR=bmg_g21 -DMAC_STR=BMG_G21
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_20_1_4 -### %s 2>&1 | \
Expand Down
3 changes: 0 additions & 3 deletions clang/test/Driver/sycl-spirv-ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
// CHECK-DEFAULT-SAME:,+SPV_INTEL_fpga_argument_interfaces
// CHECK-DEFAULT-SAME:,+SPV_INTEL_fpga_invocation_pipelining_attributes
// CHECK-DEFAULT-SAME:,+SPV_INTEL_fpga_latency_control
// CHECK-DEFAULT-SAME:,+SPV_INTEL_task_sequence
// CHECK-DEFAULT-SAME:,+SPV_KHR_shader_clock
// CHECK-DEFAULT-SAME:,+SPV_INTEL_bindless_images
// CHECK-DEFAULT-SAME:,+SPV_INTEL_token_type
Expand Down Expand Up @@ -82,7 +81,6 @@
// CHECK-FPGA-HW-SAME:,+SPV_INTEL_fpga_buffer_location
// CHECK-FPGA-HW-SAME:,+SPV_INTEL_fpga_argument_interfaces
// CHECK-FPGA-HW-SAME:,+SPV_INTEL_fpga_latency_control
// CHECK-FPGA-HW-SAME:,+SPV_INTEL_task_sequence
// CHECK-FPGA-HW-SAME:,+SPV_INTEL_usm_storage_classes
// CHECK-FPGA-HW-SAME:,+SPV_INTEL_runtime_aligned
// CHECK-FPGA-HW-SAME:,+SPV_INTEL_fpga_cluster_attributes,+SPV_INTEL_loop_fuse
Expand Down Expand Up @@ -114,7 +112,6 @@
// CHECK-CPU-SAME:,+SPV_INTEL_fpga_argument_interfaces
// CHECK-CPU-SAME:,+SPV_INTEL_fpga_invocation_pipelining_attributes
// CHECK-CPU-SAME:,+SPV_INTEL_fpga_latency_control
// CHECK-CPU-SAME:,+SPV_INTEL_task_sequence
// CHECK-CPU-SAME:,+SPV_INTEL_token_type
// CHECK-CPU-SAME:,+SPV_INTEL_bfloat16_conversion
// CHECK-CPU-SAME:,+SPV_INTEL_joint_matrix
Expand Down
15 changes: 11 additions & 4 deletions libdevice/fallback-complex-fp64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,14 @@ double __complex__ __devicelib_cexp(double __complex__ z) {
return z;
}
double __e = __spirv_ocl_exp(z_real);
return CMPLX((__e * __spirv_ocl_cos(z_imag)),
(__e * __spirv_ocl_sin(z_imag)));
double ret_real = __e * __spirv_ocl_cos(z_imag);
double ret_imag = __e * __spirv_ocl_sin(z_imag);

if (__spirv_IsNan(ret_real))
ret_real = 0.;
if (__spirv_IsNan(ret_imag))
ret_imag = 0.;
return CMPLX(ret_real, ret_imag);
}

DEVICE_EXTERN_C_INLINE
Expand Down Expand Up @@ -249,8 +255,9 @@ double __complex__ __devicelib_ctanh(double __complex__ z) {
double z_imag = __devicelib_cimag(z);
if (__spirv_IsInf(z_real)) {
if (!__spirv_IsFinite(z_imag))
return CMPLX(1.0, 0.0);
return CMPLX(1.0, __spirv_ocl_copysign(0.0, __spirv_ocl_sin(2.0 * z_imag)));
return CMPLX(__spirv_ocl_copysign(1.0, z_real), 0.0);
return CMPLX(__spirv_ocl_copysign(1.0, z_real),
__spirv_ocl_copysign(0.0, __spirv_ocl_sin(2.0 * z_imag)));
}
if (__spirv_IsNan(z_real) && z_imag == 0)
return z;
Expand Down
14 changes: 10 additions & 4 deletions libdevice/fallback-complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,14 @@ float __complex__ __devicelib_cexpf(float __complex__ z) {
return z;
}
float __e = __spirv_ocl_exp(z_real);
return CMPLXF((__e * __spirv_ocl_cos(z_imag)),
(__e * __spirv_ocl_sin(z_imag)));
float ret_real = __e * __spirv_ocl_cos(z_imag);
float ret_imag = __e * __spirv_ocl_sin(z_imag);

if (__spirv_IsNan(ret_real))
ret_real = 0.f;
if (__spirv_IsNan(ret_imag))
ret_imag = 0.f;
return CMPLXF(ret_real, ret_imag);
}

DEVICE_EXTERN_C_INLINE
Expand Down Expand Up @@ -249,8 +255,8 @@ float __complex__ __devicelib_ctanhf(float __complex__ z) {
float z_imag = __devicelib_cimagf(z);
if (__spirv_IsInf(z_real)) {
if (!__spirv_IsFinite(z_imag))
return CMPLXF(1.0f, 0.0f);
return CMPLXF(1.0f,
return CMPLXF(__spirv_ocl_copysign(1.0f, z_real), 0.0f);
return CMPLXF(__spirv_ocl_copysign(1.0f, z_real),
__spirv_ocl_copysign(0.0f, __spirv_ocl_sin(2.0f * z_imag)));
}
if (__spirv_IsNan(z_real) && z_imag == 0)
Expand Down
110 changes: 77 additions & 33 deletions libdevice/sanitizer_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ bool MemIsZero(__SYCL_GLOBAL__ const char *beg, uptr size) {
/// ASAN Save Report
///

static __SYCL_CONSTANT__ const char __mem_sanitizer_report[] =
"[kernel] SanitizerReport (ErrorType=%d, IsRecover=%d)\n";

bool __asan_internal_report_save(DeviceSanitizerErrorType error_type) {
const int Expected = ASAN_REPORT_NONE;
int Desired = ASAN_REPORT_START;
Expand All @@ -339,8 +342,14 @@ bool __asan_internal_report_save(DeviceSanitizerErrorType error_type) {
if (atomicCompareAndSet(&SanitizerReport.Flag, Desired, Expected) ==
Expected) {
SanitizerReport.ErrorType = error_type;
SanitizerReport.IsRecover = false;

// Show we've done copying
atomicStore(&SanitizerReport.Flag, ASAN_REPORT_FINISH);

if (__AsanDebug)
__spirv_ocl_printf(__mem_sanitizer_report, SanitizerReport.ErrorType,
SanitizerReport.IsRecover);
return true;
}
return false;
Expand Down Expand Up @@ -419,6 +428,10 @@ bool __asan_internal_report_save(

// Show we've done copying
atomicStore(&SanitizerReport.Flag, ASAN_REPORT_FINISH);

if (__AsanDebug)
__spirv_ocl_printf(__mem_sanitizer_report, SanitizerReport.ErrorType,
SanitizerReport.IsRecover);
return true;
}
return false;
Expand All @@ -428,6 +441,32 @@ bool __asan_internal_report_save(
/// ASAN Error Reporters
///

DeviceSanitizerMemoryType GetMemoryTypeByShadowValue(int shadow_value) {
switch (shadow_value) {
case kUsmDeviceRedzoneMagic:
case kUsmDeviceDeallocatedMagic:
return DeviceSanitizerMemoryType::USM_DEVICE;
case kUsmHostRedzoneMagic:
case kUsmHostDeallocatedMagic:
return DeviceSanitizerMemoryType::USM_HOST;
case kUsmSharedRedzoneMagic:
case kUsmSharedDeallocatedMagic:
return DeviceSanitizerMemoryType::USM_SHARED;
case kPrivateLeftRedzoneMagic:
case kPrivateMidRedzoneMagic:
case kPrivateRightRedzoneMagic:
return DeviceSanitizerMemoryType::PRIVATE;
case kMemBufferRedzoneMagic:
return DeviceSanitizerMemoryType::MEM_BUFFER;
case kSharedLocalRedzoneMagic:
return DeviceSanitizerMemoryType::LOCAL;
case kDeviceGlobalRedzoneMagic:
return DeviceSanitizerMemoryType::DEVICE_GLOBAL;
default:
return DeviceSanitizerMemoryType::UNKNOWN;
}
}

void __asan_report_access_error(uptr addr, uint32_t as, size_t size,
bool is_write, uptr poisoned_addr,
const char __SYCL_CONSTANT__ *file,
Expand All @@ -442,61 +481,56 @@ void __asan_report_access_error(uptr addr, uint32_t as, size_t size,
}
// FIXME: check if shadow_address out-of-bound

DeviceSanitizerMemoryType memory_type;
DeviceSanitizerMemoryType memory_type =
GetMemoryTypeByShadowValue(shadow_value);
DeviceSanitizerErrorType error_type;

switch (shadow_value) {
case kUsmDeviceRedzoneMagic:
memory_type = DeviceSanitizerMemoryType::USM_DEVICE;
error_type = DeviceSanitizerErrorType::OUT_OF_BOUNDS;
break;
case kUsmHostRedzoneMagic:
memory_type = DeviceSanitizerMemoryType::USM_HOST;
error_type = DeviceSanitizerErrorType::OUT_OF_BOUNDS;
break;
case kUsmSharedRedzoneMagic:
memory_type = DeviceSanitizerMemoryType::USM_SHARED;
error_type = DeviceSanitizerErrorType::OUT_OF_BOUNDS;
break;
case kUsmDeviceDeallocatedMagic:
memory_type = DeviceSanitizerMemoryType::USM_DEVICE;
error_type = DeviceSanitizerErrorType::USE_AFTER_FREE;
break;
case kUsmHostDeallocatedMagic:
memory_type = DeviceSanitizerMemoryType::USM_HOST;
error_type = DeviceSanitizerErrorType::USE_AFTER_FREE;
break;
case kUsmSharedDeallocatedMagic:
memory_type = DeviceSanitizerMemoryType::USM_SHARED;
error_type = DeviceSanitizerErrorType::USE_AFTER_FREE;
break;
case kPrivateLeftRedzoneMagic:
case kPrivateMidRedzoneMagic:
case kPrivateRightRedzoneMagic:
memory_type = DeviceSanitizerMemoryType::PRIVATE;
error_type = DeviceSanitizerErrorType::OUT_OF_BOUNDS;
break;
case kMemBufferRedzoneMagic:
memory_type = DeviceSanitizerMemoryType::MEM_BUFFER;
error_type = DeviceSanitizerErrorType::OUT_OF_BOUNDS;
break;
case kSharedLocalRedzoneMagic:
memory_type = DeviceSanitizerMemoryType::LOCAL;
error_type = DeviceSanitizerErrorType::OUT_OF_BOUNDS;
break;
case kDeviceGlobalRedzoneMagic:
memory_type = DeviceSanitizerMemoryType::DEVICE_GLOBAL;
error_type = DeviceSanitizerErrorType::OUT_OF_BOUNDS;
break;
case kUsmDeviceDeallocatedMagic:
case kUsmHostDeallocatedMagic:
case kUsmSharedDeallocatedMagic:
error_type = DeviceSanitizerErrorType::USE_AFTER_FREE;
break;
default:
memory_type = DeviceSanitizerMemoryType::UNKNOWN;
error_type = DeviceSanitizerErrorType::UNKNOWN;
}

__asan_internal_report_save(addr, as, file, line, func, is_write, size,
memory_type, error_type, is_recover);
}

void __asan_report_misalign_error(uptr addr, uint32_t as, size_t size,
bool is_write, uptr poisoned_addr,
const char __SYCL_CONSTANT__ *file,
uint32_t line,
const char __SYCL_CONSTANT__ *func,
bool is_recover = false) {

auto *shadow = (__SYCL_GLOBAL__ s8 *)MemToShadow(addr, as);
while (*shadow >= 0) {
++shadow;
}
int shadow_value = *shadow;

DeviceSanitizerErrorType error_type = DeviceSanitizerErrorType::MISALIGNED;
DeviceSanitizerMemoryType memory_type =
GetMemoryTypeByShadowValue(shadow_value);

__asan_internal_report_save(addr, as, file, line, func, is_write, size,
memory_type, error_type, is_recover);
}

bool __asan_report_unknown_device() {
return __asan_internal_report_save(DeviceSanitizerErrorType::UNKNOWN_DEVICE);
}
Expand Down Expand Up @@ -589,6 +623,8 @@ inline uptr __asan_region_is_poisoned(uptr beg, uint32_t as, size_t size) {
return 0;
}

constexpr size_t AlignMask(size_t n) { return n - 1; }

} // namespace

///
Expand All @@ -599,6 +635,10 @@ inline uptr __asan_region_is_poisoned(uptr beg, uint32_t as, size_t size) {
DEVICE_EXTERN_C_NOINLINE void __asan_##type##size( \
uptr addr, uint32_t as, const char __SYCL_CONSTANT__ *file, \
uint32_t line, const char __SYCL_CONSTANT__ *func) { \
if (addr & AlignMask(size)) { \
__asan_report_misalign_error(addr, as, size, is_write, addr, file, line, \
func); \
} \
if (__asan_address_is_poisoned(addr, as, size)) { \
__asan_report_access_error(addr, as, size, is_write, addr, file, line, \
func); \
Expand All @@ -607,6 +647,10 @@ inline uptr __asan_region_is_poisoned(uptr beg, uint32_t as, size_t size) {
DEVICE_EXTERN_C_NOINLINE void __asan_##type##size##_noabort( \
uptr addr, uint32_t as, const char __SYCL_CONSTANT__ *file, \
uint32_t line, const char __SYCL_CONSTANT__ *func) { \
if (addr & AlignMask(size)) { \
__asan_report_misalign_error(addr, as, size, is_write, addr, file, line, \
func, true); \
} \
if (__asan_address_is_poisoned(addr, as, size)) { \
__asan_report_access_error(addr, as, size, is_write, addr, file, line, \
func, true); \
Expand Down
Loading

0 comments on commit affd0ba

Please sign in to comment.