intel / opencl-clang

Other
136 stars 62 forks source link

Do not apply patches if repo is a not a git repo. #539

Closed haonanya closed 4 months ago

haonanya commented 4 months ago

also drafted patches for 15,16,17,18 and main. https://github.com/intel/opencl-clang/pull/540 https://github.com/intel/opencl-clang/pull/541 https://github.com/intel/opencl-clang/pull/542 https://github.com/intel/opencl-clang/pull/543 https://github.com/intel/opencl-clang/pull/544

th0ma7 commented 4 months ago

@haonanya I tested the patch and at first glance it looked like working just fine. But when further replaying with it thru a new PR aiming for LLVM 14.x it occured that it still fails such as:

-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2") 
-- Using SPIR-V Headers from
          /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1/SPIRV-Headers
-- Checking for one of the modules 'SPIRV-Tools'
-- [OPENCL-CLANG] Using Clang source code direcotry: /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1/clang
-- [OPENCL-CLANG] Using SPIRV-LLVM-Translator source code directory: /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1/SPIRV-LLVM-Translator
-- [OPENCL-CLANG] Patching repository /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1
-- [OPENCL-CLANG] Validating release/14.x in repository
fatal: ambiguous argument 'release/14.x': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
-- [OPENCL-CLANG] ref release/14.x not exists in repository, using current HEAD:470e7a2a7c50af3b63cb4b3e3090aa38266f4978
-- [OPENCL-CLANG] Switched to a new branch 'ocl-open-140' which starts from ref : 470e7a2a7c50af3b63cb4b3e3090aa38266f4978
-- [OPENCL-CLANG] Checking if patch 1ca45b5f5725a447ded14c0096df39f2751c4e9a is present in repository
fatal: Not a valid commit name 1ca45b5f5725a447ded14c0096df39f2751c4e9a
error: sha1 information is lacking or useless (clang/lib/Frontend/InitPreprocessor.cpp).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
-- [OPENCL-CLANG] Not present - Applying: Remove __IMAGE_SUPPORT__ macro for SPIR
Patch failed at 0001 Remove __IMAGE_SUPPORT__ macro for SPIR
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

CMake Error at /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1/opencl-clang/cmake/modules/CMakeFunctions.cmake:164 (message):
  [OPENCL-CLANG] Failed to apply patch!
Call Stack (most recent call first):
  /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1/opencl-clang/CMakeLists.txt:155 (apply_patches)

-- Configuring incomplete, errors occurred!
See also "/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1/opencl-clang.build/CMakeFiles/CMakeOutput.log".
See also "/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1/opencl-clang.build/CMakeFiles/CMakeError.log".
make[2]: *** [../../mk/spksrc.cross-cmake.mk:150: cmake_configure_target] Error 1
make[2]: Leaving directory '/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140'
make[1]: *** [../../mk/spksrc.supported.mk:71: build-arch-x64-7.1] Error 1
make[1]: Leaving directory '/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140'

Although after cleaning-up the build directory and re-executing it would succeed such as:

-- Looking for include file sys/inotify.h
-- Looking for include file sys/inotify.h - found
-- Not building amdgpu-arch: hsa-runtime64 not found
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2") 
-- Using SPIR-V Headers from
          /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1/SPIRV-Headers
-- Checking for one of the modules 'SPIRV-Tools'
-- [OPENCL-CLANG] Using Clang source code direcotry: /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1/clang
-- [OPENCL-CLANG] Using SPIRV-LLVM-Translator source code directory: /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1/SPIRV-LLVM-Translator
-- [OPENCL-CLANG] Patching repository /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1
Already on 'ocl-open-140'
-- [OPENCL-CLANG] No patches in /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1/opencl-clang/patches/spirv
-- Registering Bye as a pass plugin (static build: OFF)
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    PREFERRED_LLVM_VERSION

-- Build files have been written to: /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1/opencl-clang.build
===>  Compiling for opencl-clang
===>  - Ninja compile
===>  - Ninja build path = /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1/opencl-clang-ocl-open-140//home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1/opencl-clang.build
===>  - Use NASM = 0

Further investigating showed that it had changed my branch I was working on under the spksrc repository to:

$ git status
On branch ocl-open-140
You are in the middle of an am session.
  (fix conflicts and then run "git am --continue")
  (use "git am --skip" to skip this patch)
  (use "git am --abort" to restore the original branch)

nothing to commit, working tree clean

Explaining the following messages at the second pass:

-- [OPENCL-CLANG] Patching repository /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1
Already on 'ocl-open-140'
-- [OPENCL-CLANG] No patches in /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-opencl-clang-140/work-x64-7.1/opencl-clang/patches/spirv
haonanya commented 4 months ago

Hi, @th0ma7, opencl-clang is always creating ocl-open-140 branch based on release/14.x branch when build opencl-clang, if you changes source of that branch and the changes are related to patches/clang dir, it's possible that git apply would fail. If you have ocl-open-140 branch already, git apply will not perform and just switch to ocl-open-140 branch when build opencl-clang.

th0ma7 commented 4 months ago

Well that is where the build issue is as the assumption is wrong. Make is being called from an upper level from within a totally unrelated git repository where ocl assumes wrongly that it can change branch. My use case could be seen as ocl being a nested git within the spksrc repository.

Further, to build ocl I'm directly downloading the source tar ball of the ocl-140 branch, rather than git cloning. Therefore the ocl source has no git artifact at all just like any other source package I'm building. Thus when the build process is being called it should have a way to detect this and skip the patching process.

Spksrc (git) -> work directory (git ignored) -> ocl (plain source tree)

Thus when the build is being called from make at spkrc level, the branch switching made at ocl cmake level is affecting the wrong repository and is unnecessary.

haonanya commented 4 months ago

@th0ma7 , I see, I will take a look.