Skip to content

Commit 726f8d2

Browse files
authored
[SYCL] Remove devicelib jit link (#20777)
The '-fsycl-device-lib-jit-link' option has been removed in #20326. This PR cleans up sycl-post-link and sycl runtime code to support this option. The removed code includes: 1. Analysis in sycl-post-link tool to record which device libraries are used by user's device image via image property 2. Program manager handling for device library require mask property to decide which fallback spv will be loaded and linked during execution time. 3. Program manager utils to read/load device library fallback spv files into memory and utils to link in-memory spv device library modules with user's module. --------- Signed-off-by: jinge90 <[email protected]>
1 parent 14c960f commit 726f8d2

File tree

25 files changed

+143
-1383
lines changed

25 files changed

+143
-1383
lines changed

clang/test/Driver/sycl-linker-wrapper-image.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,18 @@ int main() {
4444
// CHECK-DAG: @.sycl_offloading.target.0 = internal unnamed_addr constant [7 x i8] c"spir64\00"
4545
// CHECK-DAG: @.sycl_offloading.opts.compile.0 = internal unnamed_addr constant [1 x i8] zeroinitializer
4646
// CHECK-DAG: @.sycl_offloading.opts.link.0 = internal unnamed_addr constant [1 x i8] zeroinitializer
47-
// CHECK-DAG: @prop = internal unnamed_addr constant [17 x i8] c"DeviceLibReqMask\00"
48-
// CHECK-DAG: @__sycl_offload_prop_sets_arr = internal constant [1 x %_pi_device_binary_property_struct] [%_pi_device_binary_property_struct { ptr @prop, ptr null, i32 1, i64 0 }]
49-
// CHECK-DAG: @SYCL_PropSetName = internal unnamed_addr constant [24 x i8] c"SYCL/devicelib req mask\00"
50-
// CHECK-DAG: @prop.1 = internal unnamed_addr constant [8 x i8] c"aspects\00"
47+
// CHECK-DAG: @prop = internal unnamed_addr constant [8 x i8] c"aspects\00"
5148
// CHECK-DAG: @prop_val = internal unnamed_addr constant [8 x i8] zeroinitializer
52-
// CHECK-DAG: @__sycl_offload_prop_sets_arr.2 = internal constant [1 x %_pi_device_binary_property_struct] [%_pi_device_binary_property_struct { ptr @prop.1, ptr @prop_val, i32 2, i64 8 }]
53-
// CHECK-DAG: @SYCL_PropSetName.3 = internal unnamed_addr constant [25 x i8] c"SYCL/device requirements\00"
54-
// CHECK-DAG: @SYCL_PropSetName.4 = internal unnamed_addr constant [22 x i8] c"SYCL/kernel param opt\00"
55-
// CHECK-DAG: @__sycl_offload_prop_sets_arr.5 = internal constant [3 x %_pi_device_binary_property_set_struct] [%_pi_device_binary_property_set_struct { ptr @SYCL_PropSetName, ptr @__sycl_offload_prop_sets_arr, ptr getelementptr ([1 x %_pi_device_binary_property_struct], ptr @__sycl_offload_prop_sets_arr, i64 0, i64 1) }, %_pi_device_binary_property_set_struct { ptr @SYCL_PropSetName.3, ptr @__sycl_offload_prop_sets_arr.2, ptr getelementptr ([1 x %_pi_device_binary_property_struct], ptr @__sycl_offload_prop_sets_arr.2, i64 0, i64 1) }, %_pi_device_binary_property_set_struct { ptr @SYCL_PropSetName.4, ptr null, ptr null }]
49+
// CHECK-DAG: @__sycl_offload_prop_sets_arr = internal constant [1 x %_pi_device_binary_property_struct] [%_pi_device_binary_property_struct { ptr @prop, ptr @prop_val, i32 2, i64 8 }]
50+
// CHECK-DAG: @SYCL_PropSetName = internal unnamed_addr constant [25 x i8] c"SYCL/device requirements\00"
51+
// CHECK-DAG: @SYCL_PropSetName.1 = internal unnamed_addr constant [22 x i8] c"SYCL/kernel param opt\00"
52+
// CHECK-DAG: @__sycl_offload_prop_sets_arr.2 = internal constant [2 x %_pi_device_binary_property_set_struct] [%_pi_device_binary_property_set_struct { ptr @SYCL_PropSetName, ptr @__sycl_offload_prop_sets_arr, ptr getelementptr ([1 x %_pi_device_binary_property_struct], ptr @__sycl_offload_prop_sets_arr, i64 0, i64 1) }, %_pi_device_binary_property_set_struct { ptr @SYCL_PropSetName.1, ptr null, ptr null }]
5653
// CHECK-DAG: @.sycl_offloading.0.data = internal unnamed_addr constant [912 x i8]
5754
// CHECK-DAG: @__sycl_offload_entry_name = internal unnamed_addr constant [25 x i8] c"_ZTSZ4mainE11fake_kernel\00"
5855
// CHECK-DAG: @__sycl_offload_entries_arr = internal constant [1 x %struct.__tgt_offload_entry] [%struct.__tgt_offload_entry { i64 0, i16 1, i16 8, i32 0, ptr null, ptr @__sycl_offload_entry_name, i64 0, i64 0, ptr null }]
5956
// CHECK-DAG: @.sycl_offloading.0.info = internal local_unnamed_addr constant [2 x i64] [i64 ptrtoint (ptr @.sycl_offloading.0.data to i64), i64 912], section ".tgtimg", align 16
6057
// CHECK-DAG: @llvm.used = appending global [1 x ptr] [ptr @.sycl_offloading.0.info], section "llvm.metadata"
61-
// CHECK-DAG: @.sycl_offloading.device_images = internal unnamed_addr constant [1 x %__sycl.tgt_device_image] [%__sycl.tgt_device_image { i16 3, i8 4, i8 0, ptr @.sycl_offloading.target.0, ptr @.sycl_offloading.opts.compile.0, ptr @.sycl_offloading.opts.link.0, ptr @.sycl_offloading.0.data, ptr getelementptr ([912 x i8], ptr @.sycl_offloading.0.data, i64 0, i64 912), ptr @__sycl_offload_entries_arr, ptr getelementptr ([1 x %struct.__tgt_offload_entry], ptr @__sycl_offload_entries_arr, i64 0, i64 1), ptr @__sycl_offload_prop_sets_arr.5, ptr getelementptr ([3 x %_pi_device_binary_property_set_struct], ptr @__sycl_offload_prop_sets_arr.5, i64 0, i64 3) }]
58+
// CHECK-DAG: @.sycl_offloading.device_images = internal unnamed_addr constant [1 x %__sycl.tgt_device_image] [%__sycl.tgt_device_image { i16 3, i8 4, i8 0, ptr @.sycl_offloading.target.0, ptr @.sycl_offloading.opts.compile.0, ptr @.sycl_offloading.opts.link.0, ptr @.sycl_offloading.0.data, ptr getelementptr ([912 x i8], ptr @.sycl_offloading.0.data, i64 0, i64 912), ptr @__sycl_offload_entries_arr, ptr getelementptr ([1 x %struct.__tgt_offload_entry], ptr @__sycl_offload_entries_arr, i64 0, i64 1), ptr @__sycl_offload_prop_sets_arr.2, ptr getelementptr ([2 x %_pi_device_binary_property_set_struct], ptr @__sycl_offload_prop_sets_arr.2, i64 0, i64 2) }]
6259
// CHECK-DAG: @.sycl_offloading.descriptor = internal constant %__sycl.tgt_bin_desc { i16 1, i16 1, ptr @.sycl_offloading.device_images, ptr null, ptr null }
6360
// CHECK-DAG: @llvm.global_ctors = {{.*}} { i32 1, ptr @sycl.descriptor_reg, ptr null }]
6461
// CHECK-DAG: @llvm.global_dtors = {{.*}} { i32 1, ptr @sycl.descriptor_unreg, ptr null }]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===----- SYCLDeviceLibBF16.h - get SYCL devicelib required Info -----=-==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
namespace llvm {
12+
class Function;
13+
class Module;
14+
bool isSYCLDeviceLibBF16Used(const Module &M);
15+
bool isBF16DeviceLibFuncDecl(const Function &F);
16+
} // namespace llvm

llvm/include/llvm/SYCLLowerIR/SYCLDeviceLibReqMask.h

Lines changed: 0 additions & 47 deletions
This file was deleted.

llvm/include/llvm/SYCLPostLink/ComputeModuleRuntimeInfo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#pragma once
1212

1313
#include "llvm/ADT/SetVector.h"
14-
#include "llvm/SYCLLowerIR/SYCLDeviceLibReqMask.h"
1514
#include "llvm/Support/PropertySetIO.h"
1615
#include <string>
1716
namespace llvm {

llvm/include/llvm/Support/PropertySetIO.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@ class PropertySetRegistry {
209209
"SYCL/specialization constants";
210210
static constexpr char SYCL_SPEC_CONSTANTS_DEFAULT_VALUES[] =
211211
"SYCL/specialization constants default values";
212-
// TODO: remove SYCL_DEVICELIB_REQ_MASK when devicelib online linking path
213-
// is totally removed.
214-
static constexpr char SYCL_DEVICELIB_REQ_MASK[] = "SYCL/devicelib req mask";
215212
static constexpr char SYCL_DEVICELIB_METADATA[] = "SYCL/devicelib metadata";
216213
static constexpr char SYCL_KERNEL_PARAM_OPT_INFO[] = "SYCL/kernel param opt";
217214
static constexpr char SYCL_PROGRAM_METADATA[] = "SYCL/program metadata";

llvm/lib/SYCLLowerIR/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ add_llvm_component_library(LLVMSYCLLowerIR
4848
SYCLAddOptLevelAttribute.cpp
4949
SYCLConditionalCallOnDevice.cpp
5050
SYCLCreateNVVMAnnotations.cpp
51-
SYCLDeviceLibReqMask.cpp
51+
SYCLDeviceLibBF16.cpp
5252
SYCLDeviceRequirements.cpp
5353
SYCLKernelParamOptInfo.cpp
5454
SYCLJointMatrixTransform.cpp
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//==----- SYCLDeviceLibBF16.cpp - get SYCL BF16 devicelib required Info ----==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
// This file provides some utils to analyze whether user's device image does
9+
// depend on sycl bfloat16 device library functions.
10+
//===----------------------------------------------------------------------===//
11+
12+
#include "llvm/SYCLLowerIR/SYCLDeviceLibBF16.h"
13+
#include "llvm/ADT/SmallVector.h"
14+
#include "llvm/IR/Function.h"
15+
#include "llvm/IR/Module.h"
16+
#include "llvm/TargetParser/Triple.h"
17+
18+
static constexpr char DEVICELIB_FUNC_PREFIX[] = "__devicelib_";
19+
20+
using namespace llvm;
21+
22+
static llvm::SmallVector<StringRef, 14> BF16DeviceLibFuncs = {
23+
"__devicelib_ConvertFToBF16INTEL",
24+
"__devicelib_ConvertBF16ToFINTEL",
25+
"__devicelib_ConvertFToBF16INTELVec1",
26+
"__devicelib_ConvertBF16ToFINTELVec1",
27+
"__devicelib_ConvertFToBF16INTELVec2",
28+
"__devicelib_ConvertBF16ToFINTELVec2",
29+
"__devicelib_ConvertFToBF16INTELVec3",
30+
"__devicelib_ConvertBF16ToFINTELVec3",
31+
"__devicelib_ConvertFToBF16INTELVec4",
32+
"__devicelib_ConvertBF16ToFINTELVec4",
33+
"__devicelib_ConvertFToBF16INTELVec8",
34+
"__devicelib_ConvertBF16ToFINTELVec8",
35+
"__devicelib_ConvertFToBF16INTELVec16",
36+
"__devicelib_ConvertBF16ToFINTELVec16",
37+
};
38+
39+
bool llvm::isSYCLDeviceLibBF16Used(const Module &M) {
40+
if (!Triple(M.getTargetTriple()).isSPIROrSPIRV())
41+
return false;
42+
43+
for (auto Fn : BF16DeviceLibFuncs) {
44+
Function *BF16Func = M.getFunction(Fn);
45+
if (BF16Func && BF16Func->isDeclaration())
46+
return true;
47+
}
48+
49+
return false;
50+
}
51+
52+
bool llvm::isBF16DeviceLibFuncDecl(const Function &F) {
53+
if (!F.isDeclaration() || !F.getName().starts_with(DEVICELIB_FUNC_PREFIX))
54+
return false;
55+
for (auto BFunc : BF16DeviceLibFuncs) {
56+
if (!F.getName().compare(BFunc))
57+
return true;
58+
}
59+
60+
return false;
61+
}

0 commit comments

Comments
 (0)