Skip to content

Commit 9c6f3a1

Browse files
Modify files to enable build L0 from tag or commit
1 parent c238ace commit 9c6f3a1

File tree

2 files changed

+157
-39
lines changed

2 files changed

+157
-39
lines changed

devops/scripts/install_drivers.sh

Lines changed: 126 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
2-
32
set -e
43
set -x
54
set -o pipefail
@@ -52,8 +51,62 @@ function get_pre_release_igfx() {
5251
if [ "$GITHUB_TOKEN" != "" ]; then
5352
HEADER="Authorization: Bearer $GITHUB_TOKEN"
5453
fi
55-
curl -L -H "$HEADER" -H "Accept: application/vnd.github.v3+json" $URL -o $HASH.zip
56-
unzip $HASH.zip && rm $HASH.zip
54+
55+
WORK_DIR="/tmp/igc-download"
56+
mkdir -p "$WORK_DIR"
57+
cd "$WORK_DIR"
58+
59+
curl -L -H "$HEADER" -H "Accept: application/vnd.github.v3+json" "$URL" -o "$HASH.zip"
60+
61+
unzip "$HASH.zip"
62+
rm "$HASH.zip"
63+
64+
# Move deb files back to the calling directory if any exist
65+
if ls *.deb 1> /dev/null 2>&1; then
66+
mv *.deb /tmp/
67+
cd /tmp/
68+
fi
69+
70+
# Clean up work directory
71+
rm -rf "$WORK_DIR"
72+
}
73+
74+
function build_level_zero_from_source() {
75+
COMMIT=$1
76+
77+
apt-get update -qq
78+
apt-get install -y build-essential cmake git libc6-dev linux-libc-dev
79+
80+
BUILD_DIR="/tmp/level-zero-build"
81+
INSTALL_DIR="/tmp/level-zero-install"
82+
rm -rf $BUILD_DIR $INSTALL_DIR
83+
mkdir -p $BUILD_DIR $INSTALL_DIR
84+
cd $BUILD_DIR
85+
86+
git clone https://github.com/oneapi-src/level-zero.git
87+
88+
cd level-zero
89+
git checkout $COMMIT
90+
91+
mkdir build
92+
cd build
93+
94+
cmake .. \
95+
-DCMAKE_BUILD_TYPE=Release \
96+
-DCMAKE_INSTALL_PREFIX=/usr/local \
97+
-DLEVEL_ZERO_BUILD_TESTS=OFF \
98+
-DLEVEL_ZERO_BUILD_SAMPLES=OFF
99+
100+
make -j$(nproc)
101+
make install DESTDIR=$INSTALL_DIR
102+
103+
cp -r $INSTALL_DIR/usr/local/* /usr/local/
104+
105+
ldconfig
106+
107+
rm -rf $BUILD_DIR $INSTALL_DIR
108+
109+
echo "Level Zero built and installed successfully from commit $COMMIT"
57110
}
58111

59112
TBB_INSTALLED=false
@@ -96,6 +149,15 @@ CheckIGCdevTag() {
96149
fi
97150
}
98151

152+
CheckIfCommitHash() {
153+
local arg="$1"
154+
if [[ $arg =~ ^[a-f0-9]{40}$ ]]; then
155+
echo "Yes"
156+
else
157+
echo "No"
158+
fi
159+
}
160+
99161
InstallIGFX () {
100162
echo "Installing Intel Graphics driver..."
101163
echo "Compute Runtime version $CR_TAG"
@@ -122,10 +184,28 @@ InstallIGFX () {
122184
| grep ".*deb" \
123185
| grep -v "u18" \
124186
| wget -qi -
125-
get_release oneapi-src/level-zero $L0_TAG \
126-
| grep ".*$UBUNTU_VER.*deb$" \
127-
| wget -qi -
128-
dpkg -i --force-all *.deb && rm *.deb *.sum
187+
188+
# Check if L0_TAG is a commit hash or a regular tag
189+
IS_L0_COMMIT=$(CheckIfCommitHash $L0_TAG)
190+
if [ "$IS_L0_COMMIT" == "Yes" ]; then
191+
echo "Level Zero is using commit hash, building from source..."
192+
if ! build_level_zero_from_source $L0_TAG; then
193+
exit 1
194+
fi
195+
# Install other packages (Level Zero was already installed from source)
196+
if ls *.deb 1> /dev/null 2>&1; then
197+
dpkg -i --force-all *.deb && rm *.deb
198+
fi
199+
if ls *.sum 1> /dev/null 2>&1; then
200+
rm *.sum
201+
fi
202+
else
203+
get_release oneapi-src/level-zero $L0_TAG \
204+
| grep ".*$UBUNTU_VER.*deb$" \
205+
| wget -qi -
206+
# Install all packages including Level Zero
207+
dpkg -i --force-all *.deb && rm *.deb *.sum
208+
fi
129209
mkdir -p /usr/local/lib/igc/
130210
echo "$IGC_TAG" > /usr/local/lib/igc/IGCTAG.txt
131211
if [ "$IS_IGC_DEV" == "Yes" ]; then
@@ -134,22 +214,50 @@ InstallIGFX () {
134214
# Backup and install it from release igc as a temporarily workaround
135215
# while we working to resolve the issue.
136216
echo "Backup libopencl-clang"
137-
cp -d /usr/local/lib/libopencl-clang2.so.15* .
138-
echo "Download IGC dev git hash $IGC_DEV_VER"
217+
218+
# Ensure we're in a writable directory for backup operations
219+
BACKUP_DIR="/tmp/igc-backup"
220+
mkdir -p "$BACKUP_DIR"
221+
cd "$BACKUP_DIR"
222+
echo "Working in backup directory: $BACKUP_DIR"
223+
224+
if ls /usr/local/lib/libopencl-clang2.so.15* 1> /dev/null 2>&1; then
225+
cp -d /usr/local/lib/libopencl-clang2.so.15* .
226+
LIBOPENCL_BACKED_UP=true
227+
echo "Successfully backed up libopencl-clang files"
228+
else
229+
echo "Warning: libopencl-clang2.so.15* not found, skipping backup"
230+
LIBOPENCL_BACKED_UP=false
231+
fi
139232
get_pre_release_igfx $IGC_DEV_URL $IGC_DEV_VER
140233
echo "Install IGC dev git hash $IGC_DEV_VER"
141234
# New dev IGC packaged iga64 conflicting with iga64 from intel-igc-media
142235
# force overwrite to workaround it first.
143-
dpkg -i --force-all *.deb
144-
echo "Install libopencl-clang"
145-
# Workaround only, will download deb and install with dpkg once fixed.
146-
cp -d libopencl-clang2.so.15* /usr/local/lib/
147-
rm /usr/local/lib/libigc.so /usr/local/lib/libigc.so.1* && \
148-
ln -s /usr/local/lib/libigc.so.2 /usr/local/lib/libigc.so && \
149-
ln -s /usr/local/lib/libigc.so.2 /usr/local/lib/libigc.so.1
236+
if ls *.deb 1> /dev/null 2>&1; then
237+
dpkg -i --force-all *.deb
238+
fi
239+
if [ "$LIBOPENCL_BACKED_UP" == "true" ]; then
240+
echo "Install libopencl-clang"
241+
# Workaround only, will download deb and install with dpkg once fixed.
242+
echo "Copying backed up libopencl-clang files from $BACKUP_DIR"
243+
cp -d "$BACKUP_DIR"/libopencl-clang2.so.15* /usr/local/lib/
244+
fi
245+
if [ -f /usr/local/lib/libigc.so.2 ]; then
246+
rm -f /usr/local/lib/libigc.so /usr/local/lib/libigc.so.1* && \
247+
ln -s /usr/local/lib/libigc.so.2 /usr/local/lib/libigc.so && \
248+
ln -s /usr/local/lib/libigc.so.2 /usr/local/lib/libigc.so.1
249+
fi
150250
echo "Clean up"
151-
rm *.deb libopencl-clang2.so.15*
251+
if ls *.deb 1> /dev/null 2>&1; then
252+
rm *.deb
253+
fi
152254
echo "$IGC_DEV_TAG" > /usr/local/lib/igc/IGCTAG.txt
255+
256+
# Clean up backup directory (this also removes the backed up libopencl-clang files)
257+
if [ -d "$BACKUP_DIR" ]; then
258+
echo "Cleaning up backup directory: $BACKUP_DIR"
259+
rm -rf "$BACKUP_DIR"
260+
fi
153261
fi
154262
}
155263

@@ -169,6 +277,7 @@ InstallCPURT () {
169277
if [ -e $INSTALL_LOCATION/oclcpu/install.sh ]; then \
170278
bash -x $INSTALL_LOCATION/oclcpu/install.sh
171279
else
280+
mkdir -p /etc/OpenCL/vendors
172281
echo $INSTALL_LOCATION/oclcpu/x64/libintelocl.so > /etc/OpenCL/vendors/intel_oclcpu.icd
173282
fi
174283
}

unified-runtime/cmake/FetchLevelZero.cmake

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,37 @@ find_package(PkgConfig QUIET)
1212
# LevelZero doesn't install a CMake config target, just PkgConfig,
1313
# so try using that to find the install and if it's not available
1414
# just try to search for the path.
15-
if(PkgConfig_FOUND)
16-
pkg_check_modules(level-zero level-zero>=1.25.0)
17-
if(level-zero_FOUND)
18-
set(LEVEL_ZERO_INCLUDE_DIR "${level-zero_INCLUDEDIR}/level_zero")
19-
set(LEVEL_ZERO_LIBRARY_SRC "${level-zero_LIBDIR}")
20-
set(LEVEL_ZERO_LIB_NAME "${level-zero_LIBRARIES}")
21-
message(STATUS "Level Zero Adapter: Using preinstalled level zero loader at ${level-zero_LINK_LIBRARIES}")
22-
endif()
23-
else()
24-
set(L0_HEADER_PATH "loader/ze_loader.h")
25-
find_path(L0_HEADER ${L0_HEADER_PATH} ${CMAKE_PREFIX_PATH} PATH_SUFFIXES "level_zero")
26-
find_library(ZE_LOADER NAMES ze_loader HINTS /usr ${CMAKE_PREFIX_PATH})
27-
if(L0_HEADER AND ZE_LOADER)
28-
set(LEVEL_ZERO_INCLUDE_DIR "${L0_HEADER}")
29-
set(LEVEL_ZERO_LIBRARY "${ZE_LOADER}")
30-
message(STATUS "Level Zero Adapter: Using preinstalled level zero loader at ${LEVEL_ZERO_LIBRARY}")
31-
add_library(ze_loader INTERFACE)
15+
16+
set(UR_LEVEL_ZERO_LOADER_REPO "https://github.com/oneapi-src/level-zero.git")
17+
# Remember to update the pkg_check_modules minimum version above when updating the
18+
# clone tag
19+
# Depending on your needs, you can set in UR_LEVEL_ZERO_LOADER_TAG here either a tag or a commit.
20+
# Release version must be coherent both in a variable and in the below if-statement.
21+
set(UR_LEVEL_ZERO_LOADER_TAG v1.25.0)
22+
23+
string(LENGTH "${UR_LEVEL_ZERO_LOADER_TAG}" TAG_LENGTH)
24+
message("${UR_LEVEL_ZERO_LOADER_TAG}")
25+
26+
27+
if (NOT (TAG_LENGTH EQUAL 40))
28+
if(PkgConfig_FOUND)
29+
pkg_check_modules(level-zero level-zero>=1.25.0)
30+
if(level-zero_FOUND)
31+
set(LEVEL_ZERO_INCLUDE_DIR "${level-zero_INCLUDEDIR}/level_zero")
32+
set(LEVEL_ZERO_LIBRARY_SRC "${level-zero_LIBDIR}")
33+
set(LEVEL_ZERO_LIB_NAME "${level-zero_LIBRARIES}")
34+
message(STATUS "Level Zero Adapter: Using preinstalled level zero loader at ${level-zero_LINK_LIBRARIES}")
35+
endif()
36+
else()
37+
set(L0_HEADER_PATH "loader/ze_loader.h")
38+
find_path(L0_HEADER ${L0_HEADER_PATH} ${CMAKE_PREFIX_PATH} PATH_SUFFIXES "level_zero")
39+
find_library(ZE_LOADER NAMES ze_loader HINTS /usr ${CMAKE_PREFIX_PATH})
40+
if(L0_HEADER AND ZE_LOADER)
41+
set(LEVEL_ZERO_INCLUDE_DIR "${L0_HEADER}")
42+
set(LEVEL_ZERO_LIBRARY "${ZE_LOADER}")
43+
message(STATUS "Level Zero Adapter: Using preinstalled level zero loader at ${LEVEL_ZERO_LIBRARY}")
44+
add_library(ze_loader INTERFACE)
45+
endif()
3246
endif()
3347
endif()
3448

@@ -47,11 +61,6 @@ if(NOT LEVEL_ZERO_LIB_NAME AND NOT LEVEL_ZERO_LIBRARY)
4761
endif()
4862
set(BUILD_STATIC ON)
4963

50-
set(UR_LEVEL_ZERO_LOADER_REPO "https://github.com/oneapi-src/level-zero.git")
51-
# Remember to update the pkg_check_modules minimum version above when updating the
52-
# clone tag
53-
set(UR_LEVEL_ZERO_LOADER_TAG v1.25.0)
54-
5564
# Disable due to a bug https://github.com/oneapi-src/level-zero/issues/104
5665
set(CMAKE_INCLUDE_CURRENT_DIR OFF)
5766
# Prevent L0 loader from exporting extra symbols

0 commit comments

Comments
 (0)