11#! /bin/bash
2- 
32set  -e
43set  -x
54set  -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
59112TBB_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+ 
99161InstallIGFX  () {
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}
0 commit comments