Skip to content

Commit

Permalink
Merge branch 'sycl' into work_group_static
Browse files Browse the repository at this point in the history
  • Loading branch information
Naghasan committed Nov 28, 2024
2 parents af1bc10 + a024380 commit b728c9c
Show file tree
Hide file tree
Showing 235 changed files with 3,502 additions and 2,985 deletions.
6 changes: 3 additions & 3 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ sycl/include/sycl/detail/ur.hpp @intel/unified-runtime-reviewers
sycl/source/detail/posix_ur.cpp @intel/unified-runtime-reviewers
sycl/source/detail/ur.cpp @intel/unified-runtime-reviewers
sycl/source/detail/windows_ur.cpp @intel/unified-runtime-reviewers
sycl/test-e2e/Plugin/ @intel/unified-runtime-reviewers
sycl/test-e2e/Adapters/ @intel/unified-runtime-reviewers

# Win Proxy Loader
sycl/pi_win_proxy_loader @intel/llvm-reviewers-runtime
sycl/test-e2e/Plugin/dll-detach-order.cpp @intel/llvm-reviewers-runtime
sycl/ur_win_proxy_loader @intel/llvm-reviewers-runtime
sycl/test-e2e/Adapters/dll-detach-order.cpp @intel/llvm-reviewers-runtime

# CUDA specific runtime implementations
sycl/include/sycl/ext/oneapi/experimental/cuda/ @intel/llvm-reviewers-cuda
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/sycl-linux-precommit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ jobs:
image: ghcr.io/intel/llvm/ubuntu2204_build:latest
image_options: -u 1001 --gpus all --cap-add SYS_ADMIN
target_devices: ext_oneapi_cuda:gpu
- name: AMD/HIP
runner: '["Linux", "amdgpu"]'
image: ghcr.io/intel/llvm/ubuntu2204_build:latest
image_options: -u 1001 --device=/dev/dri --device=/dev/kfd
target_devices: ext_oneapi_hip:gpu
reset_intel_gpu: false
- name: Intel
runner: '["Linux", "gen12"]'
image: ghcr.io/intel/llvm/ubuntu2204_intel_drivers:latest
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ To contribute:
- [The seven rules of a great Git commit message](https://cbea.ms/git-commit)
are recommended read and follow.
- To a reasonable extent, title tags can be used to signify the component
changed, e.g.: `[PI]`, `[CUDA]`, `[Doc]`.
changed, e.g.: `[UR]`, `[CUDA]`, `[Doc]`.
- Create a pull request (PR) for your changes following
[Creating a pull request instructions](https://help.github.com/articles/creating-a-pull-request/).
- Make sure PR has a good description explaining all of the changes made,
Expand Down
10 changes: 6 additions & 4 deletions buildbot/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def do_configure(args):
if sys.platform != "darwin":
sycl_enabled_backends.append("level_zero")

# lld is needed on Windows or for the HIP plugin on AMD
# lld is needed on Windows or for the HIP adapter on AMD
if platform.system() == "Windows" or (args.hip and args.hip_platform == "AMD"):
llvm_enable_projects += ";lld"

Expand Down Expand Up @@ -152,8 +152,8 @@ def do_configure(args):
libclc_targets_to_build += libclc_nvidia_target_names
libclc_gen_remangled_variants = "ON"

if args.enable_plugin:
sycl_enabled_backends += args.enable_plugin
if args.enable_backends:
sycl_enabled_backends += args.enable_backends

if args.disable_preview_lib:
sycl_preview_lib = "OFF"
Expand Down Expand Up @@ -374,7 +374,9 @@ def main():
parser.add_argument(
"--ci-defaults", action="store_true", help="Enable default CI parameters"
)
parser.add_argument("--enable-plugin", action="append", help="Enable SYCL plugin")
parser.add_argument(
"--enable-backends", action="append", help="Enable SYCL backend"
)
parser.add_argument(
"--disable-preview-lib",
action="store_true",
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Driver/OffloadBundler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,12 +687,12 @@ class ObjectFileHandler final : public FileHandler {
if (Error Err = Symbol.printName(NameOS))
return std::move(Err);

// If we are dealing with a bitcode file do not add special globals
// llvm.used and llvm.compiler.used and __AsanDeviceGlobalMetadata to
// If we are dealing with a bitcode file do not add special globals to
// the list of defined symbols.
if (SF->isIR() &&
(Name == "llvm.used" || Name == "llvm.compiler.used" ||
Name == "__AsanDeviceGlobalMetadata"))
Name == "__AsanDeviceGlobalMetadata" ||
Name == "__AsanKernelMetadata"))
continue;

// Add symbol name with the target prefix to the buffer.
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Driver/SanitizerArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,9 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,

CmdArgs.push_back("-mllvm");
CmdArgs.push_back("-asan-mapping-scale=4");

addSpecialCaseListOpt(Args, CmdArgs,
"-fsanitize-ignorelist=", UserIgnorelistFiles);
}
return;
}
Expand Down
8 changes: 4 additions & 4 deletions devops/dependencies-igc-dev.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"linux": {
"igc_dev": {
"github_tag": "igc-dev-ac93a93",
"version": "ac93a93",
"updated_at": "2024-11-21T02:09:35Z",
"url": "https://api.github.com/repos/intel/intel-graphics-compiler/actions/artifacts/2216471673/zip",
"github_tag": "igc-dev-7dad678",
"version": "7dad678",
"updated_at": "2024-11-24T10:48:51Z",
"url": "https://api.github.com/repos/intel/intel-graphics-compiler/actions/artifacts/2229466354/zip",
"root": "{DEPS_ROOT}/opencl/runtime/linux/oclgpu"
}
}
Expand Down
29 changes: 29 additions & 0 deletions libdevice/sanitizer/asan_rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,16 @@ constexpr size_t AlignMask(size_t n) { return n - 1; }
///
/// ASAN Load/Store Report Built-ins
///
/// NOTE:
/// if __AsanLaunchInfo equals 0, the sanitizer is disabled for this launch
///

#define ASAN_REPORT_ERROR_BASE(type, is_write, size, as) \
DEVICE_EXTERN_C_NOINLINE void __asan_##type##size##_as##as( \
uptr addr, const char __SYCL_CONSTANT__ *file, uint32_t line, \
const char __SYCL_CONSTANT__ *func) { \
if (!__AsanLaunchInfo) \
return; \
if (addr & AlignMask(size)) { \
__asan_report_misalign_error(addr, as, size, is_write, addr, file, line, \
func); \
Expand All @@ -682,6 +687,8 @@ constexpr size_t AlignMask(size_t n) { return n - 1; }
DEVICE_EXTERN_C_NOINLINE void __asan_##type##size##_as##as##_noabort( \
uptr addr, const char __SYCL_CONSTANT__ *file, uint32_t line, \
const char __SYCL_CONSTANT__ *func) { \
if (!__AsanLaunchInfo) \
return; \
if (addr & AlignMask(size)) { \
__asan_report_misalign_error(addr, as, size, is_write, addr, file, line, \
func, true); \
Expand Down Expand Up @@ -714,6 +721,8 @@ ASAN_REPORT_ERROR(store, true, 16)
DEVICE_EXTERN_C_NOINLINE void __asan_##type##N_as##as( \
uptr addr, size_t size, const char __SYCL_CONSTANT__ *file, \
uint32_t line, const char __SYCL_CONSTANT__ *func) { \
if (!__AsanLaunchInfo) \
return; \
if (auto poisoned_addr = __asan_region_is_poisoned(addr, as, size)) { \
__asan_report_access_error(addr, as, size, is_write, poisoned_addr, \
file, line, func); \
Expand All @@ -722,6 +731,8 @@ ASAN_REPORT_ERROR(store, true, 16)
DEVICE_EXTERN_C_NOINLINE void __asan_##type##N_as##as##_noabort( \
uptr addr, size_t size, const char __SYCL_CONSTANT__ *file, \
uint32_t line, const char __SYCL_CONSTANT__ *func) { \
if (!__AsanLaunchInfo) \
return; \
if (auto poisoned_addr = __asan_region_is_poisoned(addr, as, size)) { \
__asan_report_access_error(addr, as, size, is_write, poisoned_addr, \
file, line, func, true); \
Expand All @@ -743,6 +754,9 @@ ASAN_REPORT_ERROR_N(store, true)
///

DEVICE_EXTERN_C_NOINLINE uptr __asan_mem_to_shadow(uptr ptr, uint32_t as) {
if (!__AsanLaunchInfo)
return 0;

return MemToShadow(ptr, as);
}

Expand All @@ -756,6 +770,9 @@ static __SYCL_CONSTANT__ const char __mem_set_shadow_local[] =
DEVICE_EXTERN_C_NOINLINE void
__asan_set_shadow_static_local(uptr ptr, size_t size,
size_t size_with_redzone) {
if (!__AsanLaunchInfo)
return;

// Since ptr is aligned to ASAN_SHADOW_GRANULARITY,
// if size != aligned_size, then the buffer tail of ptr is not aligned
uptr aligned_size = RoundUpTo(size, ASAN_SHADOW_GRANULARITY);
Expand Down Expand Up @@ -795,6 +812,9 @@ static __SYCL_CONSTANT__ const char __mem_unpoison_shadow_static_local_end[] =
DEVICE_EXTERN_C_NOINLINE void
__asan_unpoison_shadow_static_local(uptr ptr, size_t size,
size_t size_with_redzone) {
if (!__AsanLaunchInfo)
return;

ASAN_DEBUG(__spirv_ocl_printf(__mem_unpoison_shadow_static_local_begin));

auto shadow_begin = MemToShadow(ptr + size, ADDRESS_SPACE_LOCAL);
Expand Down Expand Up @@ -828,6 +848,9 @@ static __SYCL_CONSTANT__ const char __mem_report_arg_count_incorrect[] =

DEVICE_EXTERN_C_NOINLINE void
__asan_set_shadow_dynamic_local(uptr ptr, uint32_t num_args) {
if (!__AsanLaunchInfo)
return;

ASAN_DEBUG(__spirv_ocl_printf(__mem_set_shadow_dynamic_local_begin));

auto *launch_info = (__SYCL_GLOBAL__ const LaunchInfo *)__AsanLaunchInfo;
Expand Down Expand Up @@ -859,6 +882,9 @@ static __SYCL_CONSTANT__ const char __mem_unpoison_shadow_dynamic_local_end[] =

DEVICE_EXTERN_C_NOINLINE void
__asan_unpoison_shadow_dynamic_local(uptr ptr, uint32_t num_args) {
if (!__AsanLaunchInfo)
return;

ASAN_DEBUG(__spirv_ocl_printf(__mem_unpoison_shadow_dynamic_local_begin));

auto *launch_info = (__SYCL_GLOBAL__ const LaunchInfo *)__AsanLaunchInfo;
Expand Down Expand Up @@ -895,6 +921,9 @@ static __SYCL_CONSTANT__ const char __mem_set_shadow_private[] =

DEVICE_EXTERN_C_NOINLINE void __asan_set_shadow_private(uptr begin, uptr size,
char val) {
if (!__AsanLaunchInfo)
return;

ASAN_DEBUG(__spirv_ocl_printf(__mem_set_shadow_private_begin));

auto *launch_info = (__SYCL_GLOBAL__ const LaunchInfo *)__AsanLaunchInfo;
Expand Down
23 changes: 23 additions & 0 deletions llvm/include/llvm/SYCLLowerIR/AsanKernelMetadata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- AsanKernelMetadata.h - fix kernel medatadata for sanitizer ---===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// This pass fixes attributes and metadata of the global variable
// "__AsanKernelMetadata"
//===----------------------------------------------------------------------===//

#pragma once

#include "llvm/IR/PassManager.h"

namespace llvm {

class AsanKernelMetadataPass : public PassInfoMixin<AsanKernelMetadataPass> {
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
};

} // namespace llvm
63 changes: 63 additions & 0 deletions llvm/lib/SYCLLowerIR/AsanKernelMetadata.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//===-- AsanKernelMetadata.cpp - fix kernel medatadata for sanitizer -===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// This pass fixes attributes and metadata of global variable
// "__AsanKernelMetadata".
// We treat "__AsanKernelMetadata" as a device global variable, so that it can
// be read by runtime.
// "spirv.Decorations" is removed by llvm-link, so we add it here again.
//===----------------------------------------------------------------------===//

#include "llvm/SYCLLowerIR/AsanKernelMetadata.h"

#include "llvm/IR/IRBuilder.h"

#define DEBUG_TYPE "AsanKernelMetadata"

using namespace llvm;

namespace llvm {

constexpr StringRef SPIRV_DECOR_MD_KIND = "spirv.Decorations";
constexpr uint32_t SPIRV_HOST_ACCESS_DECOR = 6147;

PreservedAnalyses AsanKernelMetadataPass::run(Module &M,
ModuleAnalysisManager &MAM) {
auto *KernelMetadata = M.getNamedGlobal("__AsanKernelMetadata");
if (!KernelMetadata) {
return PreservedAnalyses::all();
}

auto &DL = M.getDataLayout();
auto &Ctx = M.getContext();

// Fix attributes
KernelMetadata->addAttribute(
"sycl-device-global-size",
std::to_string(DL.getTypeAllocSize(KernelMetadata->getValueType())));

// Fix metadata
unsigned MDKindID = Ctx.getMDKindID(SPIRV_DECOR_MD_KIND);

SmallVector<Metadata *, 1> MDOps;

SmallVector<Metadata *, 3> MD;
auto *Ty = Type::getInt32Ty(Ctx);
MD.push_back(ConstantAsMetadata::get(
Constant::getIntegerValue(Ty, APInt(32, SPIRV_HOST_ACCESS_DECOR))));
MD.push_back(
ConstantAsMetadata::get(Constant::getIntegerValue(Ty, APInt(32, 0))));
MD.push_back(MDString::get(Ctx, "_Z20__AsanKernelMetadata"));

MDOps.push_back(MDNode::get(Ctx, MD));

KernelMetadata->addMetadata(MDKindID, *MDNode::get(Ctx, MDOps));

return PreservedAnalyses::none();
}

} // namespace llvm
1 change: 1 addition & 0 deletions llvm/lib/SYCLLowerIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ add_llvm_component_library(LLVMSYCLLowerIR
SYCLPropagateJointMatrixUsage.cpp
SYCLVirtualFunctionsAnalysis.cpp
SYCLUtils.cpp
AsanKernelMetadata.cpp

LocalAccessorToSharedMemory.cpp
GlobalOffset.cpp
Expand Down
11 changes: 1 addition & 10 deletions llvm/lib/SYCLLowerIR/ComputeModuleRuntimeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,7 @@ getSYCLESIMDSplitStatusFromMetadata(const Module &M) {
} // namespace

bool isModuleUsingAsan(const Module &M) {
for (const auto &F : M) {
if (F.getCallingConv() != CallingConv::SPIR_KERNEL)
continue;
if (F.arg_size() == 0)
continue;
const auto *LastArg = F.getArg(F.arg_size() - 1);
if (LastArg->getName() == "__asan_launch")
return true;
}
return false;
return M.getNamedGlobal("__AsanKernelMetadata");
}

// This function traverses over reversed call graph by BFS algorithm.
Expand Down
Loading

0 comments on commit b728c9c

Please sign in to comment.