Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hello, looks like something broke circa commit 47f05fad43621aa1637427d857d639d0ecfbb7cd #107

Open
hydra3333 opened this issue Apr 22, 2020 · 39 comments

Comments

@hydra3333
Copy link

Hello.
Something broke within the last 10 days. It used to work.
Probably 47f05fa
Cross-compiling under ubuntu 18.04.3 for target Win10x64.

[14:17:54][DEBUG] Running 'ninja -j 4 ' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[1/4] Building CXX object CMakeFiles/OpenCL.dir/loader/windows/icd_windows_apppackage.cpp.obj
FAILED: CMakeFiles/OpenCL.dir/loader/windows/icd_windows_apppackage.cpp.obj 
/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-g++ --sysroot=/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32  -DCL_TARGET_OPENCL_VERSION=220 -DOpenCL_EXPORTS -Iinc -I. -Iloader -O3  -fstack-protector-all  -D_FORTIFY_SOURCE=2 -O3 -DNDEBUG -MD -MT CMakeFiles/OpenCL.dir/loader/windows/icd_windows_apppackage.cpp.obj -MF CMakeFiles/OpenCL.dir/loader/windows/icd_windows_apppackage.cpp.obj.d -o CMakeFiles/OpenCL.dir/loader/windows/icd_windows_apppackage.cpp.obj -c loader/windows/icd_windows_apppackage.cpp
loader/windows/icd_windows_apppackage.cpp:27:10: fatal error: windows.management.deployment.h: No such file or directory
   27 | #include <windows.management.deployment.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
[2/4] Building C object CMakeFiles/OpenCL.dir/loader/windows/icd_windows_envvars.c.obj
[3/4] Building C object CMakeFiles/OpenCL.dir/loader/windows/icd_windows_hkr.c.obj
FAILED: CMakeFiles/OpenCL.dir/loader/windows/icd_windows_hkr.c.obj 
/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-gcc --sysroot=/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32 -DCL_TARGET_OPENCL_VERSION=220 -DOpenCL_EXPORTS -Iinc -I. -Iloader -O3  -fstack-protector-all  -D_FORTIFY_SOURCE=2 -O3 -DNDEBUG -MD -MT CMakeFiles/OpenCL.dir/loader/windows/icd_windows_hkr.c.obj -MF CMakeFiles/OpenCL.dir/loader/windows/icd_windows_hkr.c.obj.d -o CMakeFiles/OpenCL.dir/loader/windows/icd_windows_hkr.c.obj   -c loader/windows/icd_windows_hkr.c
loader/windows/icd_windows_hkr.c: In function 'khrIcdOsVendorsEnumerateHKR':
loader/windows/icd_windows_hkr.c:217:21: error: 'CM_GETIDLIST_FILTER_CLASS' undeclared (first use in this function); did you mean 'CM_GETIDLIST_FILTER_BITS'?
  217 |     ULONG ulFlags = CM_GETIDLIST_FILTER_CLASS |
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                     CM_GETIDLIST_FILTER_BITS
loader/windows/icd_windows_hkr.c:217:21: note: each undeclared identifier is reported only once for each function it appears in
loader/windows/icd_windows_hkr.c:218:21: error: 'CM_GETIDLIST_FILTER_PRESENT' undeclared (first use in this function); did you mean 'CM_GETIDLIST_FILTER_BITS'?
  218 |                     CM_GETIDLIST_FILTER_PRESENT;
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                     CM_GETIDLIST_FILTER_BITS
loader/windows/icd_windows_hkr.c:343:22: error: 'DEVPKEY_Device_ClassGuid' undeclared (first use in this function)
  343 |                     &DEVPKEY_Device_ClassGuid,
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.
@bashbaug
Copy link
Contributor

Hello, thanks for the report, and I'm sorry to hear that we broke your build.

Since these changes are needed for OpenCLOn12 I don't think we can back them out. Can you say more how your cross-compilation toolchain works? Is there an update that might provide the missing header file?

Worst-case we could selectively disable this part of the build, but because ICD loaders without this functionality will not enumerate OpenCLOn12 I think we should consider this a last resort.

Once we get this fixed I'd also be interested in adding this configuration to our Travis builds. Is this something you could help with?

Thanks!

@hydra3333
Copy link
Author

Hi. Thanks for your cool work.

Can you say more how your cross-compilation toolchain works?
Sure.
In a VM with Ubuntu 18.04.3 -

  • install Mingw64,
  • build GCC under Mingw64 so the target of compilation with it is Win10x64
  • run a script which uses these to build OpenCL-ICD-Loader as a dependency library for a static ffmpeg.exe
  • copy the resulting ffmpeg.exe to a Win10 machine to run.
  • below is a log from a successful build using a commit prior to the "offending" commit

I'm not sure where windows.management.deployment.h comes from, I guess it is installed as a part of some microsoft developer tool ?
I just searched the C: drive of a Win10X64Pro PC (with no developer tools on it) and no such file exists.
It doesn't seem to be something native, or Mingw64 would have included windows.management.deployment.h ?
It appears possible you may have introduced a new compilation dependency on a specific product used by the build process ?
I did a quick google for windows.management.deployment.h and there's nothing "obviously free" easily spotted.
If that is the case, then it precludes (many?) people cross-compiling tools like ffmpeg and using OpenCL.
I'm not sure what windows.management.deployment.h is used by/for, is there some other way to do the same thing ?

I don't know anything about Travis builds although I'd be happy to provide the Ubuntu commands to download and setup Mingw64/GCC if you like.

Cheers !

./cross_compiler_v100_001.py --force -d opencl_icd

[16:04:07][INFO] Loaded 173 packages
[16:04:07][DEBUG] Debugging is on
[16:04:07][INFO] Starting custom build process for: opencl_icd
[16:04:07][INFO] Starting build script
Changing dir from /home/u/Desktop/_working to /home/u/Desktop/_working/workdir
[16:04:07][DEBUG] cd /home/u/Desktop/_working/workdir
[16:04:07][INFO] MinGW-w64 install is working! (target mingw64)
[16:04:07][INFO] Building dependencies of 'opencl_icd'
[16:04:07][INFO] Building dependency 'opencl_headers'
[16:04:07][DEBUG] Reset CFLAGS/CXXFLAGS/CPPFLAGS/LDFLAGS to: '  -O3  -fstack-protector-all  -D_FORTIFY_SOURCE=2  '
##############################
Changing dir from /home/u/Desktop/_working/workdir to /home/u/Desktop/_working/workdir/x86_64
[16:04:07][DEBUG] cd /home/u/Desktop/_working/workdir/x86_64
Changing dir from /home/u/Desktop/_working/workdir/x86_64 to OpenCL-Headers_git
[16:04:07][DEBUG] cd OpenCL-Headers_git
[16:04:07][DEBUG] git remote update
[16:04:07][DEBUG] Running 'git remote update' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-Headers_git'
Fetching origin
[16:04:08][DEBUG] git checkout -f
[16:04:08][DEBUG] Running 'git checkout -f' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-Headers_git'
Your branch is up to date with 'origin/master'.
[16:04:08][DEBUG] git checkout master
[16:04:08][DEBUG] Running 'git checkout master' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-Headers_git'
Already on 'master'
Your branch is up to date with 'origin/master'.
[16:04:08][DEBUG] ####################
[16:04:08][DEBUG] Up to date
[16:04:08][DEBUG] LOCAL:  0f87a32ae17ef6c709317fda321d96f35c081480

[16:04:08][DEBUG] REMOTE: 0f87a32ae17ef6c709317fda321d96f35c081480

[16:04:08][DEBUG] BASE:   0f87a32ae17ef6c709317fda321d96f35c081480

[16:04:08][DEBUG] ####################
Changing dir from /home/u/Desktop/_working/workdir/x86_64/OpenCL-Headers_git to ..
[16:04:08][DEBUG] cd ..
Changing dir from /home/u/Desktop/_working/workdir/x86_64 to OpenCL-Headers_git
[16:04:08][DEBUG] cd OpenCL-Headers_git
Changing dir from /home/u/Desktop/_working/workdir/x86_64/OpenCL-Headers_git to ..
[16:04:08][DEBUG] cd ..
[16:04:08][INFO] Building dependency 'opencl_headers': Done!
[16:04:08][DEBUG] Reset CFLAGS/CXXFLAGS/CPPFLAGS/LDFLAGS to: '  -O3  -fstack-protector-all  -D_FORTIFY_SOURCE=2  '
##############################
##############################
Changing dir from /home/u/Desktop/_working/workdir/x86_64 to ..
[16:04:08][DEBUG] cd ..
[16:04:08][INFO] Building dependency 'opencl_icd'
[16:04:08][DEBUG] Reset CFLAGS/CXXFLAGS/CPPFLAGS/LDFLAGS to: '  -O3  -fstack-protector-all  -D_FORTIFY_SOURCE=2  '
Changing dir from /home/u/Desktop/_working/workdir to /home/u/Desktop/_working/workdir/x86_64
[16:04:08][DEBUG] cd /home/u/Desktop/_working/workdir/x86_64
Changing dir from /home/u/Desktop/_working/workdir/x86_64 to OpenCL-ICD-Loader_git
[16:04:08][DEBUG] cd OpenCL-ICD-Loader_git
[16:04:08][DEBUG] git remote update
[16:04:08][DEBUG] Running 'git remote update' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
Fetching origin
[16:04:09][DEBUG] git checkout -f
[16:04:09][DEBUG] Running 'git checkout -f' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[16:04:09][DEBUG] git checkout 6d0b214b9cc303cdb0b05b3c0dc9afb0c39998c5
[16:04:09][DEBUG] Running 'git checkout 6d0b214b9cc303cdb0b05b3c0dc9afb0c39998c5' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
HEAD is now at 6d0b214 Add a path separator to OCL_ICD_VENDORS
[16:04:09][DEBUG] ####################
[16:04:09][DEBUG] Up to date
[16:04:09][DEBUG] LOCAL:  6d0b214b9cc303cdb0b05b3c0dc9afb0c39998c5

[16:04:09][DEBUG] REMOTE: 6d0b214b9cc303cdb0b05b3c0dc9afb0c39998c5

[16:04:09][DEBUG] BASE:   6d0b214b9cc303cdb0b05b3c0dc9afb0c39998c5

[16:04:09][DEBUG] ####################
Changing dir from /home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git to ..
[16:04:09][DEBUG] cd ..
Changing dir from /home/u/Desktop/_working/workdir/x86_64 to OpenCL-ICD-Loader_git
[16:04:09][DEBUG] cd OpenCL-ICD-Loader_git
[16:04:09][DEBUG] git clean -ffdx
[16:04:09][DEBUG] Running 'git clean -ffdx' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
Removing .ninja_deps
Removing .ninja_log
Removing 0001-OpenCL-git-prefix.patch
Removing 0002-OpenCL-git-header.patch
Removing CMakeCache.txt
Removing CMakeFiles/
Removing OpenCL.dll
Removing already_ran_cmake_e749e8c408b7cfd5e51bdac05573e921
Removing already_ran_make_087932b193324f9c3a5c5ff3bc128a3a
Removing already_ran_make_install
Removing build.ninja
Removing cmake_install.cmake
Removing icd_cmake_config.h
Removing libOpenCL.dll.a
Removing loader/windows/icd_windows_envvars.c.bak
Removing patch_96cf9a77ded223d88af7689b8ddfeb24.done
Removing patch_fddf82259d545a3939c37de72ef5b4e1.done
Removing rules.ninja
[16:04:09][DEBUG] git submodule foreach --recursive git clean -ffdx
[16:04:09][DEBUG] Running 'git submodule foreach --recursive git clean -ffdx' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[16:04:09][DEBUG] git reset --hard
[16:04:09][DEBUG] Running 'git reset --hard' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
HEAD is now at 6d0b214 Add a path separator to OCL_ICD_VENDORS
[16:04:09][DEBUG] git submodule foreach --recursive git reset --hard
[16:04:09][DEBUG] Running 'git submodule foreach --recursive git reset --hard' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[16:04:09][DEBUG] git submodule update --init --recursive
[16:04:09][DEBUG] Running 'git submodule update --init --recursive' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[16:04:09][DEBUG] Applying patch 'opencl/0001-OpenCL-git-prefix.patch' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[16:04:09][INFO] Copying patch from '/home/u/Desktop/_working/patches/opencl/0001-OpenCL-git-prefix.patch' to '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git/0001-OpenCL-git-prefix.patch'
[16:04:09][DEBUG] cp -f "/home/u/Desktop/_working/patches/opencl/0001-OpenCL-git-prefix.patch" "/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git/0001-OpenCL-git-prefix.patch" # copy file 
[16:04:09][INFO] Patching source using: '0001-OpenCL-git-prefix.patch'
[16:04:09][DEBUG] patch -p1 < "0001-OpenCL-git-prefix.patch"
[16:04:09][DEBUG] Running 'patch -p1 < "0001-OpenCL-git-prefix.patch"' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
patching file CMakeLists.txt
[16:04:09][DEBUG] Applying patch 'opencl/0002-OpenCL-git-header.patch' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[16:04:09][INFO] Copying patch from '/home/u/Desktop/_working/patches/opencl/0002-OpenCL-git-header.patch' to '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git/0002-OpenCL-git-header.patch'
[16:04:09][DEBUG] cp -f "/home/u/Desktop/_working/patches/opencl/0002-OpenCL-git-header.patch" "/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git/0002-OpenCL-git-header.patch" # copy file 
[16:04:09][INFO] Patching source using: '0002-OpenCL-git-header.patch'
[16:04:09][DEBUG] patch -p1 < "0002-OpenCL-git-header.patch"
[16:04:09][DEBUG] Running 'patch -p1 < "0002-OpenCL-git-header.patch"' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
patching file loader/windows/icd_windows_hkr.h
[16:04:09][INFO] Running run_post_regexreplace-command: 'sed -i.bak 's/Windows.h/windows.h/' ./loader/windows/icd_windows_envvars.c'
[16:04:09][DEBUG] Running 'sed -i.bak 's/Windows.h/windows.h/' ./loader/windows/icd_windows_envvars.c' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[16:04:09][INFO] C-Making 'opencl_icd' with: . -DCMAKE_TOOLCHAIN_FILE="/home/u/Desktop/_working/workdir/mingw_toolchain.cmake" -G"Ninja" -DCMAKE_INSTALL_PREFIX=/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DOPENCL_ICD_LOADER_REQUIRE_WDK=OFF
[16:04:09][DEBUG] cmake . -DCMAKE_TOOLCHAIN_FILE="/home/u/Desktop/_working/workdir/mingw_toolchain.cmake" -G"Ninja" -DCMAKE_INSTALL_PREFIX=/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DOPENCL_ICD_LOADER_REQUIRE_WDK=OFF
[16:04:09][DEBUG] Running 'cmake . -DCMAKE_TOOLCHAIN_FILE="/home/u/Desktop/_working/workdir/mingw_toolchain.cmake" -G"Ninja" -DCMAKE_INSTALL_PREFIX=/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DOPENCL_ICD_LOADER_REQUIRE_WDK=OFF' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
-- The C compiler identification is GNU 10.0.1
-- The CXX compiler identification is GNU 10.0.1
-- Check for working C compiler: /home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-gcc
-- Check for working C compiler: /home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-g++
-- Check for working CXX compiler: /home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Looking for secure_getenv
-- Looking for secure_getenv - not found
-- Looking for __secure_getenv
-- Looking for __secure_getenv - not found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git
[16:04:10][DEBUG] make clean
[16:04:10][DEBUG] Running 'make clean' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
make: *** No rule to make target 'clean'.  Stop.
[16:04:10][INFO][NINJA] Building 'opencl_icd' with 'build_options':  in /home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git
[16:04:10][DEBUG] ninja -j 4 
[16:04:10][DEBUG] Running 'ninja -j 4 ' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[1/8] Building C object CMakeFiles/OpenCL.dir/loader/windows/icd_windows_dxgk.c.obj
[2/8] Building C object CMakeFiles/OpenCL.dir/loader/windows/icd_windows.c.obj
In file included from loader/windows/icd_windows.c:21:
loader/windows/icd_windows_hkr.h:40:19: warning: 'DEVPKEY_Device_ClassGuid' initialized and declared 'extern'
   40 | DEFINE_DEVPROPKEY(DEVPKEY_Device_ClassGuid,              0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 10);    // DEVPROP_TYPE_GUID
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~
loader/windows/icd_windows_hkr.h:38:126: note: in definition of macro 'DEFINE_DEVPROPKEY'
   38 | #define DEFINE_DEVPROPKEY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8, pid) extern const DEVPROPKEY_2 DECLSPEC_SELECTANY name = { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }, pid }
      |                                                                                                                              ^~~~
loader/windows/icd_windows.c: In function 'khrIcdOsVendorsEnumerate':
loader/windows/icd_windows.c:192:64: warning: passing argument 2 of 'pCreateDXGIFactory' from incompatible pointer type [-Wincompatible-pointer-types]
  192 |             HRESULT hr = pCreateDXGIFactory(&IID_IDXGIFactory, &pFactory);
      |                                                                ^~~~~~~~~
      |                                                                |
      |                                                                IDXGIFactory **
loader/windows/icd_windows.c:192:64: note: expected 'void **' but argument is of type 'IDXGIFactory **'
loader/windows/icd_windows.c: In function 'khrIcdOsVendorsEnumerateOnce':
loader/windows/icd_windows.c:244:5: warning: implicit declaration of function 'InitOnceExecuteOnce' [-Wimplicit-function-declaration]
  244 |     InitOnceExecuteOnce(&initialized, khrIcdOsVendorsEnumerate, NULL, NULL);
      |     ^~~~~~~~~~~~~~~~~~~
[3/8] Building C object CMakeFiles/OpenCL.dir/loader/icd.c.obj
[4/8] Building RC object CMakeFiles/OpenCL.dir/loader/windows/OpenCL.rc.res
[5/8] Building C object CMakeFiles/OpenCL.dir/loader/windows/icd_windows_envvars.c.obj
[6/8] Building C object CMakeFiles/OpenCL.dir/loader/icd_dispatch.c.obj
[7/8] Building C object CMakeFiles/OpenCL.dir/loader/windows/icd_windows_hkr.c.obj
In file included from loader/windows/icd_windows_hkr.c:20:
loader/windows/icd_windows_hkr.h:40:19: warning: 'DEVPKEY_Device_ClassGuid' initialized and declared 'extern'
   40 | DEFINE_DEVPROPKEY(DEVPKEY_Device_ClassGuid,              0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 10);    // DEVPROP_TYPE_GUID
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~
loader/windows/icd_windows_hkr.h:38:126: note: in definition of macro 'DEFINE_DEVPROPKEY'
   38 | #define DEFINE_DEVPROPKEY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8, pid) extern const DEVPROPKEY_2 DECLSPEC_SELECTANY name = { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }, pid }
      |                                                                                                                              ^~~~
loader/windows/icd_windows_hkr.c: In function 'khrIcdOsVendorsEnumerateHKR':
loader/windows/icd_windows_hkr.c:343:21: warning: passing argument 2 of 'CM_Get_DevNode_PropertyW' from incompatible pointer type [-Wincompatible-pointer-types]
  343 |                     &DEVPKEY_Device_ClassGuid,
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                     |
      |                     const DEVPROPKEY_2 * {aka const struct _DEVPROPKEY_2 *}
In file included from loader/windows/icd_windows_hkr.c:23:
/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/include/cfgmgr32.h:839:88: note: expected 'const DEVPROPKEY *' but argument is of type 'const DEVPROPKEY_2 *' {aka 'const struct _DEVPROPKEY_2 *'}
  839 |   CMAPI CONFIGRET WINAPI CM_Get_DevNode_PropertyW(DEVINST dnDevInst, const DEVPROPKEY *PropertyKey, DEVPROPTYPE *PropertyType, PBYTE PropertyBuffer, PULONG PropertyBufferSize, ULONG ulFlags);
      |                                                                      ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
[8/8] Linking C shared library OpenCL.dll
[16:04:11][INFO] Running post-build-command: 'cp -vf "libOpenCL.dll.a" "/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32/lib/libOpenCL.dll.a"'
[16:04:11][DEBUG] cp -vf "libOpenCL.dll.a" "/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32/lib/libOpenCL.dll.a"
[16:04:11][DEBUG] Running 'cp -vf "libOpenCL.dll.a" "/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32/lib/libOpenCL.dll.a"' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
'libOpenCL.dll.a' -> '/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32/lib/libOpenCL.dll.a'
[16:04:11][INFO] Running post-build-command: 'cp -vf "libOpenCL.dll.a" "/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32/lib/libOpenCL.a"'
[16:04:11][DEBUG] cp -vf "libOpenCL.dll.a" "/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32/lib/libOpenCL.a"
[16:04:11][DEBUG] Running 'cp -vf "libOpenCL.dll.a" "/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32/lib/libOpenCL.a"' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
'libOpenCL.dll.a' -> '/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32/lib/libOpenCL.a'
[16:04:11][INFO] Running post-build-command: 'if [ ! -f "already_ran_make_install" ] ; then touch already_ran_make_install ; fi'
[16:04:11][DEBUG] if [ ! -f "already_ran_make_install" ] ; then touch already_ran_make_install ; fi
[16:04:11][DEBUG] Running 'if [ ! -f "already_ran_make_install" ] ; then touch already_ran_make_install ; fi' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
Changing dir from /home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git to ..
[16:04:11][DEBUG] cd ..
[16:04:11][INFO] Building dependency 'opencl_icd': Done!
[16:04:11][DEBUG] Reset CFLAGS/CXXFLAGS/CPPFLAGS/LDFLAGS to: '  -O3  -fstack-protector-all  -D_FORTIFY_SOURCE=2  '
##############################
Changing dir from /home/u/Desktop/_working/workdir/x86_64 to ..
[16:04:11][DEBUG] cd ..
Changing dir from /home/u/Desktop/_working/workdir to ..
[16:04:11][DEBUG] cd ..

@hydra3333
Copy link
Author

Oh dear.

If we copy windows.management.deployment.h" and use that in the cross-compile build process,
we soon discover that it contains other includes which are also missing files.
eg AsyncInfo.h

ICD_LOADER now has specific dependencies for which there are no readily available sources to use in cross-compilation.

Is there another way ?

@bashbaug
Copy link
Contributor

Thanks for a very detailed reply!

Regarding this step:

  • run a script which uses these to build OpenCL-ICD-Loader as a dependency library for a static ffmpeg.exe

Does your build process only use the static import library OpenCL.lib (or in your case libOpenCL.dll.a)? Specifically, can you please confirm that you never use or distribute the OpenCL.dll you build?

I'm guessing this is the case since you are currently building with -DOPENCL_ICD_LOADER_REQUIRE_WDK=OFF, but I'd like to double-check.

If so, I think we can add a similar control to skip the section of the ICD loader for OpenCLOn12. Similar to -DOPENCL_ICD_LOADER_REQUIRE_WDK=OFF - which we ironically were recently able to remove to simplify the build - this control shouldn't be used to compile an OpenCL.dll because some ICDs won't be enumerated, but it should be fine for your purpose.

If this sounds good I'll create a PR with this change to try.

@MathiasMagnus
Copy link
Contributor

AFAICT the missing header is part of the Windows Runtime, hence the loader picks up the Windows SDK as a dependency. The dependency is not only for bringing in types and defines but there is significant new logic for OpenCLOn12, and without calling out the gist of it, it's hard to imagine making it work without COM/WRL/WinRT, so the Win SDK in general.

The Windows SDK is installed under Program Files (x86), and said header on my system is found for all installed SDK versions installed:

PS C:\Users\mnagy> gci 'C:\Program Files (x86)\Windows Kits\10\' -rec -fil windows.management.deployment.h


    Directory: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\cppwinrt\winrt

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---       2018. 10. 23.     0:35         138348 Windows.Management.Deployment.h

    Directory: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\winrt

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---       2018. 10. 23.     0:37         379955 windows.management.deployment.h

    Directory: C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\cppwinrt\winrt

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---       2019. 03. 18.    17:25         138348 Windows.Management.Deployment.h

    Directory: C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\winrt

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---       2019. 03. 18.    17:26         381033 windows.management.deployment.h

The standalone Windows 10 SDK may be installed from here, although 99% of systems likely install it (like me) via the Visual Studio (Build Tools or IDE) installer.

I'm not a minGW user and don't know how CMake behaves when used with minGW. I don't have the capacity to debug this all the way, create an int main() with a single function invocation from WinRT and check which includes/links are missing.

In non-cross compilation scenarios CMake detects the SDK version and stores it in a variable per the docs.

@jenatali
Copy link
Contributor

Oof, yeah, MinGW isn't going to support the WinRT headers anytime soon.

I think the only two options here are:

  1. Attempt to do what was done with DxgKrnl support and inline the necessary definitions to keep the code working. I haven't looked at how bad that'd be, but my guess is it's probably pretty bad.
  2. Add a compile switch for building without OpenCLOn12 support. We could probably even detect MinGW and set it automatically just for convenience.

@hydra3333: I am very curious about your response to @bashbaug regarding why you need to build the ICD loader.

@MathiasMagnus
Copy link
Contributor

@hydra3333 Is it not possible to build ffmpeg using Clang on Windows? The LLVM toolchain is pleasantly schizoid in the sense it can behave like GCC/MSVC alike while being able to produce binaries for most platforms.

We had a project where the possibility of cross-compiling of the OpenCL parts came up, but the ICD (by definition) is platform specific. It's not the best candidate for cross-compiling. I don't think ffmpeg should have many GNU/POSIX-specific code under the hood that would warrant wanting to compile the entire thing using the GNU toolchain.

Or as @jenatali said, taking a step back, what's the reason for trying to build an ICD loader?

@jenatali
Copy link
Contributor

Just to add one more thing while waiting for a response... @hydra3333: If you are truly building a "static" ffmpeg.exe like you say, using a static lib of OpenCL, that's a bad idea. One of the primary reasons for dynamic linking is to allow implementations to change/improve out from under you, as long as they support the same API. As a result, your statically-linked ffmpeg wouldn't be able to take advantage of OpenCLOn12 if that's the only OpenCL driver available on the system, either using older OpenCL ICD loaders that predate my changes, or if you end up having to compile without that support.

On the other hand, if you're just building the OpenCL ICD loader in order to get an import lib like @bashbaug suggested/hoped, and then discarding the resulting DLL, that's fine, and in that case stripping out OpenCLOn12 support just to get it compiling would be fine as well. You could even use delay-loads so that you can run when the target system doesn't have an OpenCL ICD loader available.

It'd be possible to go even further and not build the real ICD loader, and just build some stubs that have the correct import signature to generate the correct imports for ffmpeg.exe.

@hydra3333
Copy link
Author

hydra3333 commented Apr 28, 2020

Specifically, can you please confirm that you never use or distribute the OpenCL.dll you build?

This is true.

@hydra3333
Copy link
Author

The standalone Windows 10 SDK may be installed from here, although 99% of systems likely install it (like me) via the Visual Studio (Build Tools or IDE) installer.

I grabbed a temporary copy of Windows.Management.Deployment.h from the development win10 VM MS make available, it still didn't build due to it containing further includes ;)

@hydra3333
Copy link
Author

hydra3333 commented Apr 28, 2020

I am very curious about your response to @bashbaug regarding why you need to build the ICD loader.

OK. I was told the only choices were
(a) to either cross-compile-link a static ffmpeg to the ICD loader (good and easy, it dynamically loads nvidia's OpenCL.dll at runtime on the Win10 PC) ... if that's not what's happening, pls tell me!, or
(b) to use the process of

  • temporarily manually copy the currently installed OpenCL.dll installed on the WIn10 PC by the prevailing nvidia driver installer, over to ubuntu
  • use gendef & dlltool to create a libOpenCL.a and link to that

@hydra3333
Copy link
Author

hydra3333 commented Apr 28, 2020

is it not possible to build ffmpeg using Clang on Window

I'm not sure it is, especially with its tons of extenal dependencies. Perhaps.
Even MABS https://github.com/m-ab-s/media-autobuild_suite sets up a mingw environment under windows to do it.

In my case I use VMs, as I can't "pollute" my main PC with dev environment, and MS charge $ for an ongoing win10 license in a VM.

@hydra3333
Copy link
Author

If you are truly building a "static" ffmpeg.exe like you say, using a static lib of OpenCL, that's a bad idea.

yes.

@hydra3333
Copy link
Author

hydra3333 commented Apr 28, 2020

On the other hand, if you're just building the OpenCL ICD loader in order to get an import lib like @bashbaug suggested/hoped, and then discarding the resulting DLL, that's fine, and in that case stripping out OpenCLOn12 support just to get it compiling would be fine as well. You could even use delay-loads so that you can run when the target system doesn't have an OpenCL ICD loader available.
It'd be possible to go even further and not build the real ICD loader, and just build some stubs that have the correct import signature to generate the correct imports for ffmpeg.exe.

ah.
back to the drawing board for me, the way it was put to me, that's what linking to icd loader was doing :(

@hydra3333
Copy link
Author

So, sorry for your inconvenience.

@MathiasMagnus
Copy link
Contributor

MathiasMagnus commented Apr 28, 2020

@hydra3333 Regarding some of your responses:

temporarily manually copy the currently installed OpenCL.dll ... use gendef & dlltool to create a libOpenCL.a and link to that

That way you'll end up importing all the symbols into your executable, in which case it will be ffmpegs responsibility to be updated alongisde GPU drivers and always ship the latest ICD. Since this is very unlikely, vendors highly encourage dynamically linking the ICD loader. For development purposes IMHO it's fine, but not ideal for deployment and distribution.

I'm not sure it is, especially with its tons of extenal dependencies. Perhaps.

Having looked at MABS there are ineed a daunting number of dependencies. Having been converting a fair amount of GNU/Linux projects to Windows in the past decade my general remark is that often it's easier than one might think. The biggest part missing is usually the build scripts in something other than GNU Make. However, package repos have improved a lot in the past years, to extents to get ffmepg (and ALL of it's dependencies) to build on Windows is as simple as:

vcpkg install ffmpeg

I'm a prime time user (and package maintainer) of Vcpkg and the ffmpeg package supports turning on hordes of optional features as fell (simultaneously too, if you so wish):

PS C:\Users\mnagy> .\Source\Repos\vcpkg\vcpkg.exe search ffmpeg
ffmpeg               4.2-5            a library to decode, encode, transcode, mux, demux, stream, filter and play pr...
ffmpeg[ffmpeg]                        build the ffmpeg.exe application
ffmpeg[ffserver]                      ffserver appplication support in ffmpeg
ffmpeg[ffplay]                        ffplay appplication support in ffmpeg
ffmpeg[ffprobe]                       ffprobe appplication support in ffmpeg
ffmpeg[openssl]                       openssl support in ffmpeg
ffmpeg[lzma]                          lzma support in ffmpeg
ffmpeg[bzip2]                         bzip2 support in ffmpeg
ffmpeg[vpx]                           WebM VP8/VP9 support in ffmpeg
ffmpeg[x264]                          x264 support in ffmpeg
ffmpeg[opencl]                        opencl support in ffmpeg
ffmpeg[nonfree]                       allow nonfree and unredistributable libraries
ffmpeg[gpl]                           allow GPL licensed libraries
ffmpeg[version3]                      upgrade (L)GPL to version 3
ffmpeg[avresample]                    Libav audio resampling library support in ffmpeg
ffnvcodec            9.1.23.0         FFmpeg version of Nvidia Codec SDK headers.
opencv[ffmpeg]                        ffmpeg support for opencv
opencv3[ffmpeg]                       ffmpeg support for opencv
opencv4[ffmpeg]                       ffmpeg support for opencv
openimageio[ffmpeg]                   Enable ffmpeg support for openimageio

Hope this helps and perhaps even circumvents your issue altogether. All packages and their downstreams in Vcpkg build with MSVC (or Clang if you set it up that way) and patch the sources as needed, so you're not subject to all the hassle of having to cross-compile, once again which is usually a consequence of projects not maintaining CMake(/meson) build scripts. Luckily, community projects like Vcpkg help a lot in hooking up libraries to each other.

@jenatali
Copy link
Contributor

@MathiasMagnus I think you're wrong about this:

temporarily manually copy the currently installed OpenCL.dll ... use gendef & dlltool to create a libOpenCL.a and link to that

That'd be an acceptable approach I think, similar to what I had suggested around building a stub ICD loader. That should cause the resulting ffmpeg.exe to be dynamically linked against the ICD loader, not statically linked with the loader or an actual ICD. As I understand it, there does not exist any tool which can "downconvert" a DLL to a static lib for linking, only tools which can generate import libs.

@jenatali
Copy link
Contributor

jenatali commented Apr 28, 2020

Also, @hydra3333 if your response to this is correct:

Specifically, can you please confirm that you never use or distribute the OpenCL.dll you build?

This is true.

Then your ffmpeg.exe isn't actually statically linked against the loader, just against an import lib. You should be able to confirm by looking at the import table of the resulting exe. MSVC's link.exe can show this (link.exe /dump /imports <filename>), and I'm sure there exist other tools in the LLVM or MinGW that can do similar.

If that ends up being the case, then whatever modifications you need to make to this codebase don't really matter, as long as the OpenCL API entrypoints exist in the resulting DLL, and are present in the .def file, causing the import lib to be created correctly.

@hydra3333
Copy link
Author

hydra3333 commented Apr 29, 2020

@MathiasMagnus thank you very much indeed.

I have been following others' recipes and not worrying to much until something breaks to fix, learning that way, and you have clarified very clearly and well.

I'm a prime time user (and package maintainer) of Vcpkg

I am very excited to see this and will certainly take a look at it.
Perhaps I can live with the ever-expiring freely available MS Windows 10 dev environment VM download.

@hydra3333
Copy link
Author

Yes indeed. Thank you once again !

link.exe /dump /imports

Microsoft (R) COFF/PE Dumper Version 14.12.25835.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file ffmpeg.exe

File Type: EXECUTABLE IMAGE

  Section contains the following imports:

    OpenCL.dll
             147718C5C Import Address Table
             1477171A4 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference

                           1 clBuildProgram
                           3 clCreateBuffer
                           4 clCreateCommandQueue
                           6 clCreateContext
                           D clCreateImage
                          10 clCreateKernel
                          15 clCreateProgramWithSource
                          21 clEnqueueCopyImage
                          23 clEnqueueFillBuffer
                          26 clEnqueueMapImage
                          2A clEnqueueNDRangeKernel
                          2C clEnqueueReadBuffer
                          2E clEnqueueReadImage
                          36 clEnqueueUnmapMemObject
                          38 clEnqueueWriteBuffer
                          3A clEnqueueWriteImage
                          3B clFinish
                          3C clFlush
                          3F clGetDeviceIDs
                          40 clGetDeviceInfo
                          42 clGetEventProfilingInfo
                          44 clGetExtensionFunctionAddressForPlatform
                          47 clGetImageInfo
                          4B clGetMemObjectInfo
                          4D clGetPlatformIDs
                          4E clGetPlatformInfo
                          4F clGetProgramBuildInfo
                          52 clGetSupportedImageFormats
                          54 clReleaseCommandQueue
                          55 clReleaseContext
                          57 clReleaseEvent
                          58 clReleaseKernel
                          59 clReleaseMemObject
                          5A clReleaseProgram
                          5C clRetainCommandQueue
                          68 clSetKernelArg
                          6F clWaitForEvents

@bashbaug
Copy link
Contributor

Hi @hydra3333 , I just created PR #110 that adds a CMake option to disable support for the OpenCLOn12 ICD to simplify build dependencies. Can you give it a try to see if it works with your toolchain? You'll need to explicitly enable the option since the default is to support the OpenCLOn12 ICD. You can do this the same way you were explicitly setting OPENCL_ICD_LOADER_REQUIRE_WDK=OFF previously.

We're looking at some other options to simplify the build process also, but something like this is the most likely short-term solution. Thanks!

@hydra3333
Copy link
Author

hydra3333 commented May 1, 2020

@bashbaug OK, thanks I will.

In regard to OpenCLOn12, I gather this is "OpenCL 1.2 over DX12" ? per https://www.khronos.org/assets/uploads/apis/OpenCL-3.0-Launch-Apr20.pdf

I suppose I'm not missing anything for my use case by the looks anyway.

@hydra3333
Copy link
Author

hydra3333 commented May 1, 2020

:) I'm doing something wrong :) Nearly there.

Changing dir from /home/u/Desktop/_working/workdir to /home/u/Desktop/_working/workdir/x86_64
[13:37:45][DEBUG] cd /home/u/Desktop/_working/workdir/x86_64
[13:37:45][INFO] Git Cloning 'https://github.com/KhronosGroup/OpenCL-ICD-Loader.git' to '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[13:37:45][DEBUG] git clone  --progress "https://github.com/KhronosGroup/OpenCL-ICD-Loader.git" "OpenCL-ICD-Loader_git.tmp"
[13:37:45][DEBUG] Running 'git clone  --progress "https://github.com/KhronosGroup/OpenCL-ICD-Loader.git" "OpenCL-ICD-Loader_git.tmp"' in '/home/u/Desktop/_working/workdir/x86_64'
Cloning into 'OpenCL-ICD-Loader_git.tmp'...
remote: Enumerating objects: 11, done.        
remote: Counting objects: 100% (11/11), done.        
remote: Compressing objects: 100% (11/11), done.        
remote: Total 350 (delta 3), reused 3 (delta 0), pack-reused 339
Receiving objects: 100% (350/350), 204.81 KiB | 377.00 KiB/s, done.
Resolving deltas: 100% (193/193), done.
[13:37:48][DEBUG] mv "OpenCL-ICD-Loader_git.tmp" "OpenCL-ICD-Loader_git"
[13:37:48][DEBUG] Running 'mv "OpenCL-ICD-Loader_git.tmp" "OpenCL-ICD-Loader_git"' in '/home/u/Desktop/_working/workdir/x86_64'
[13:37:48][INFO] Finished GIT cloning 'https://github.com/KhronosGroup/OpenCL-ICD-Loader.git' to 'OpenCL-ICD-Loader_git'
Changing dir from /home/u/Desktop/_working/workdir/x86_64 to OpenCL-ICD-Loader_git
[13:37:48][DEBUG] cd OpenCL-ICD-Loader_git
[13:37:48][DEBUG] Running pre-patch-command pre replaceVariables (raw): 'git fetch origin  pull/110/head:xx'
[13:37:48][DEBUG] Running pre-patch-command: 'git fetch origin  pull/110/head:xx'
[13:37:48][DEBUG] git fetch origin  pull/110/head:xx
[13:37:48][DEBUG] Running 'git fetch origin  pull/110/head:xx' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
From https://github.com/KhronosGroup/OpenCL-ICD-Loader
 * [new ref]         refs/pull/110/head -> xx
[13:37:49][DEBUG] Running pre-patch-command pre replaceVariables (raw): 'git checkout xx'
[13:37:49][DEBUG] Running pre-patch-command: 'git checkout xx'
[13:37:49][DEBUG] git checkout xx
[13:37:49][DEBUG] Running 'git checkout xx' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
Switched to branch 'xx'
[13:37:49][DEBUG] git clean -ffdx
[13:37:49][DEBUG] Running 'git clean -ffdx' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[13:37:49][DEBUG] git submodule foreach --recursive git clean -ffdx
[13:37:49][DEBUG] Running 'git submodule foreach --recursive git clean -ffdx' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[13:37:49][DEBUG] git reset --hard
[13:37:49][DEBUG] Running 'git reset --hard' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
HEAD is now at 7b51bf7 expand ifdefs to remove include file dependencies
[13:37:49][DEBUG] git submodule foreach --recursive git reset --hard
[13:37:49][DEBUG] Running 'git submodule foreach --recursive git reset --hard' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[13:37:49][DEBUG] git submodule update --init --recursive
[13:37:49][DEBUG] Running 'git submodule update --init --recursive' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[13:37:49][DEBUG] Applying patch 'opencl/0001-OpenCL-git-prefix.patch' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[13:37:49][INFO] Copying patch from '/home/u/Desktop/_working/patches/opencl/0001-OpenCL-git-prefix.patch' to '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git/0001-OpenCL-git-prefix.patch'
[13:37:49][DEBUG] cp -f "/home/u/Desktop/_working/patches/opencl/0001-OpenCL-git-prefix.patch" "/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git/0001-OpenCL-git-prefix.patch" # copy file 
[13:37:49][INFO] Patching source using: '0001-OpenCL-git-prefix.patch'
[13:37:49][DEBUG] patch -p1 < "0001-OpenCL-git-prefix.patch"
[13:37:49][DEBUG] Running 'patch -p1 < "0001-OpenCL-git-prefix.patch"' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
patching file CMakeLists.txt
Hunk #1 succeeded at 78 with fuzz 1 (offset 3 lines).
[13:37:49][DEBUG] Applying patch 'opencl/0002-OpenCL-git-header.patch' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[13:37:49][INFO] Copying patch from '/home/u/Desktop/_working/patches/opencl/0002-OpenCL-git-header.patch' to '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git/0002-OpenCL-git-header.patch'
[13:37:49][DEBUG] cp -f "/home/u/Desktop/_working/patches/opencl/0002-OpenCL-git-header.patch" "/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git/0002-OpenCL-git-header.patch" # copy file 
[13:37:49][INFO] Patching source using: '0002-OpenCL-git-header.patch'
[13:37:49][DEBUG] patch -p1 < "0002-OpenCL-git-header.patch"
[13:37:49][DEBUG] Running 'patch -p1 < "0002-OpenCL-git-header.patch"' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
patching file loader/windows/icd_windows_hkr.h
[13:37:49][INFO] Running run_post_regexreplace-command: 'sed -i.bak 's/Windows.h/windows.h/' ./loader/windows/icd_windows_envvars.c'
[13:37:49][DEBUG] Running 'sed -i.bak 's/Windows.h/windows.h/' ./loader/windows/icd_windows_envvars.c' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[13:37:49][INFO] C-Making 'opencl_icd' with: . -DCMAKE_TOOLCHAIN_FILE="/home/u/Desktop/_working/workdir/mingw_toolchain.cmake" -G"Ninja" -DCMAKE_INSTALL_PREFIX=/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DOPENCL_ICD_LOADER_REQUIRE_WDK=OFF -DOPENCL_ICD_LOADER_DISABLE_OPENCLON12=ON 
[13:37:49][DEBUG] cmake . -DCMAKE_TOOLCHAIN_FILE="/home/u/Desktop/_working/workdir/mingw_toolchain.cmake" -G"Ninja" -DCMAKE_INSTALL_PREFIX=/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DOPENCL_ICD_LOADER_REQUIRE_WDK=OFF -DOPENCL_ICD_LOADER_DISABLE_OPENCLON12=ON 
[13:37:49][DEBUG] Running 'cmake . -DCMAKE_TOOLCHAIN_FILE="/home/u/Desktop/_working/workdir/mingw_toolchain.cmake" -G"Ninja" -DCMAKE_INSTALL_PREFIX=/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DOPENCL_ICD_LOADER_REQUIRE_WDK=OFF -DOPENCL_ICD_LOADER_DISABLE_OPENCLON12=ON ' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
-- The C compiler identification is GNU 10.0.1
-- The CXX compiler identification is GNU 10.0.1
-- Check for working C compiler: /home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-gcc
-- Check for working C compiler: /home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-g++
-- Check for working CXX compiler: /home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Looking for secure_getenv
-- Looking for secure_getenv - not found
-- Looking for __secure_getenv
-- Looking for __secure_getenv - not found
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    OPENCL_ICD_LOADER_REQUIRE_WDK


-- Build files have been written to: /home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git
[13:37:50][DEBUG] make clean
[13:37:50][DEBUG] Running 'make clean' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
make: *** No rule to make target 'clean'.  Stop.
[13:37:50][INFO][NINJA] Building 'opencl_icd' with 'build_options':  in /home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git
[13:37:50][DEBUG] ninja -j 4 
[13:37:50][DEBUG] Running 'ninja -j 4 ' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[1/9] Building C object CMakeFiles/OpenCL.dir/loader/windows/icd_windows_dxgk.c.obj
[2/9] Building C object CMakeFiles/OpenCL.dir/loader/windows/icd_windows.c.obj
In file included from loader/windows/icd_windows.c:21:
loader/windows/icd_windows_hkr.h:40:19: warning: 'DEVPKEY_Device_ClassGuid' initialized and declared 'extern'
   40 | DEFINE_DEVPROPKEY(DEVPKEY_Device_ClassGuid,              0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 10);    // DEVPROP_TYPE_GUID
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~
loader/windows/icd_windows_hkr.h:38:126: note: in definition of macro 'DEFINE_DEVPROPKEY'
   38 | #define DEFINE_DEVPROPKEY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8, pid) extern const DEVPROPKEY_2 DECLSPEC_SELECTANY name = { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }, pid }
      |                                                                                                                              ^~~~
loader/windows/icd_windows.c: In function 'khrIcdOsVendorsEnumerate':
loader/windows/icd_windows.c:195:64: warning: passing argument 2 of 'pCreateDXGIFactory' from incompatible pointer type [-Wincompatible-pointer-types]
  195 |             HRESULT hr = pCreateDXGIFactory(&IID_IDXGIFactory, &pFactory);
      |                                                                ^~~~~~~~~
      |                                                                |
      |                                                                IDXGIFactory **
loader/windows/icd_windows.c:195:64: note: expected 'void **' but argument is of type 'IDXGIFactory **'
loader/windows/icd_windows.c: In function 'khrIcdOsVendorsEnumerateOnce':
loader/windows/icd_windows.c:247:5: warning: implicit declaration of function 'InitOnceExecuteOnce' [-Wimplicit-function-declaration]
  247 |     InitOnceExecuteOnce(&initialized, khrIcdOsVendorsEnumerate, NULL, NULL);
      |     ^~~~~~~~~~~~~~~~~~~
[3/9] Building C object CMakeFiles/OpenCL.dir/loader/icd.c.obj
[4/9] Building C object CMakeFiles/OpenCL.dir/loader/windows/icd_windows_envvars.c.obj
[5/9] Building C object CMakeFiles/OpenCL.dir/loader/icd_dispatch.c.obj
[6/9] Building RC object CMakeFiles/OpenCL.dir/loader/windows/OpenCL.rc.res
[7/9] Building C object CMakeFiles/OpenCL.dir/loader/windows/icd_windows_hkr.c.obj
In file included from loader/windows/icd_windows_hkr.c:20:
loader/windows/icd_windows_hkr.h:40:19: warning: 'DEVPKEY_Device_ClassGuid' initialized and declared 'extern'
   40 | DEFINE_DEVPROPKEY(DEVPKEY_Device_ClassGuid,              0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 10);    // DEVPROP_TYPE_GUID
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~
loader/windows/icd_windows_hkr.h:38:126: note: in definition of macro 'DEFINE_DEVPROPKEY'
   38 | #define DEFINE_DEVPROPKEY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8, pid) extern const DEVPROPKEY_2 DECLSPEC_SELECTANY name = { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }, pid }
      |                                                                                                                              ^~~~
loader/windows/icd_windows_hkr.c: In function 'khrIcdOsVendorsEnumerateHKR':
loader/windows/icd_windows_hkr.c:343:21: warning: passing argument 2 of 'CM_Get_DevNode_PropertyW' from incompatible pointer type [-Wincompatible-pointer-types]
  343 |                     &DEVPKEY_Device_ClassGuid,
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                     |
      |                     const DEVPROPKEY_2 * {aka const struct _DEVPROPKEY_2 *}
In file included from loader/windows/icd_windows_hkr.c:23:
/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/include/cfgmgr32.h:840:88: note: expected 'const DEVPROPKEY *' but argument is of type 'const DEVPROPKEY_2 *' {aka 'const struct _DEVPROPKEY_2 *'}
  840 |   CMAPI CONFIGRET WINAPI CM_Get_DevNode_PropertyW(DEVINST dnDevInst, const DEVPROPKEY *PropertyKey, DEVPROPTYPE *PropertyType, PBYTE PropertyBuffer, PULONG PropertyBufferSize, ULONG ulFlags);
      |                                                                      ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
[8/9] Building CXX object CMakeFiles/OpenCL.dir/loader/windows/icd_windows_apppackage.cpp.obj
[9/9] Linking CXX shared library OpenCL.dll
FAILED: OpenCL.dll libOpenCL.dll.a 
: && /home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-g++ --sysroot=/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32  -O3  -fstack-protector-all  -D_FORTIFY_SOURCE=2 -O3 -DNDEBUG  -O3  -fstack-protector-all  -D_FORTIFY_SOURCE=2   loader/windows/OpenCL.def -shared -o OpenCL.dll -Wl,--out-implib,libOpenCL.dll.a -Wl,--major-image-version,0,--minor-image-version,0 CMakeFiles/OpenCL.dir/loader/icd.c.obj CMakeFiles/OpenCL.dir/loader/icd_dispatch.c.obj CMakeFiles/OpenCL.dir/loader/windows/icd_windows.c.obj CMakeFiles/OpenCL.dir/loader/windows/icd_windows_dxgk.c.obj CMakeFiles/OpenCL.dir/loader/windows/icd_windows_envvars.c.obj CMakeFiles/OpenCL.dir/loader/windows/icd_windows_hkr.c.obj CMakeFiles/OpenCL.dir/loader/windows/icd_windows_apppackage.cpp.obj CMakeFiles/OpenCL.dir/loader/windows/OpenCL.rc.res  -lcfgmgr32  -lRuntimeObject  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && :
/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/10.0.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lRuntimeObject
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
[13:37:52][ERROR] Error [1] running process: 'ninja -j 4 ' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[13:37:52][ERROR] You can try deleting the product/dependency folder: '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git' and re-run the script

patches.zip
patches and build code from https://github.com/DeadSix27/python_cross_compile_script/tree/master/patches/opencl

also of interest

CMake Warning:
  Manually-specified variables were not used by the project:

    OPENCL_ICD_LOADER_REQUIRE_WDK

@bashbaug
Copy link
Contributor

bashbaug commented May 1, 2020

OK, that's encouraging.

I just pushed one more commit that may resolve this issue. Would you mind grabbing the latest changes, or making one additional small change to your CMakeLists.txt?

-    target_link_libraries (OpenCL cfgmgr32.lib RuntimeObject.lib)
+    target_link_libraries (OpenCL cfgmgr32.lib runtimeobject.lib)

If it doesn't, could you check if you have a libruntimeobject.a on your system? See related comment here.

The CMake warning about OPENCL_ICD_LOADER_REQUIRE_WDK is expected since we recently eliminated the dependency on the Windows WDK (and hence this CMake variable).

Thanks!

@hydra3333
Copy link
Author

Beaut. Will let you know.

@hydra3333
Copy link
Author

hydra3333 commented May 2, 2020

Success !
Thank you for your patience, persistence and good work.

Changing dir from /home/u/Desktop/_working/workdir/x86_64 to ..
[14:28:43][DEBUG] cd ..
[14:28:43][INFO] Building dependency 'opencl_icd'
[14:28:43][DEBUG] Reset CFLAGS/CXXFLAGS/CPPFLAGS/LDFLAGS to: '  -O3  -fstack-protector-all  -D_FORTIFY_SOURCE=2  '
##############################
Changing dir from /home/u/Desktop/_working/workdir to /home/u/Desktop/_working/workdir/x86_64
[14:28:43][DEBUG] cd /home/u/Desktop/_working/workdir/x86_64
[14:28:43][INFO] Git Cloning 'https://github.com/KhronosGroup/OpenCL-ICD-Loader.git' to '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[14:28:43][DEBUG] git clone  --progress "https://github.com/KhronosGroup/OpenCL-ICD-Loader.git" "OpenCL-ICD-Loader_git.tmp"
[14:28:43][DEBUG] Running 'git clone  --progress "https://github.com/KhronosGroup/OpenCL-ICD-Loader.git" "OpenCL-ICD-Loader_git.tmp"' in '/home/u/Desktop/_working/workdir/x86_64'
Cloning into 'OpenCL-ICD-Loader_git.tmp'...
remote: Enumerating objects: 11, done.        
remote: Counting objects: 100% (11/11), done.        
remote: Compressing objects: 100% (11/11), done.        
remote: Total 350 (delta 3), reused 3 (delta 0), pack-reused 339        
Receiving objects: 100% (350/350), 205.19 KiB | 418.00 KiB/s, done.
Resolving deltas: 100% (192/192), done.
[14:28:45][DEBUG] mv "OpenCL-ICD-Loader_git.tmp" "OpenCL-ICD-Loader_git"
[14:28:45][DEBUG] Running 'mv "OpenCL-ICD-Loader_git.tmp" "OpenCL-ICD-Loader_git"' in '/home/u/Desktop/_working/workdir/x86_64'
[14:28:45][INFO] Finished GIT cloning 'https://github.com/KhronosGroup/OpenCL-ICD-Loader.git' to 'OpenCL-ICD-Loader_git'
Changing dir from /home/u/Desktop/_working/workdir/x86_64 to OpenCL-ICD-Loader_git
[14:28:45][DEBUG] cd OpenCL-ICD-Loader_git
[14:28:45][DEBUG] Running pre-patch-command pre replaceVariables (raw): 'git fetch origin  pull/110/head:xx'
[14:28:45][DEBUG] Running pre-patch-command: 'git fetch origin  pull/110/head:xx'
[14:28:45][DEBUG] git fetch origin  pull/110/head:xx
[14:28:45][DEBUG] Running 'git fetch origin  pull/110/head:xx' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
From https://github.com/KhronosGroup/OpenCL-ICD-Loader
 * [new ref]         refs/pull/110/head -> xx
[14:28:47][DEBUG] Running pre-patch-command pre replaceVariables (raw): 'git checkout xx'
[14:28:47][DEBUG] Running pre-patch-command: 'git checkout xx'
[14:28:47][DEBUG] git checkout xx
[14:28:47][DEBUG] Running 'git checkout xx' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
Switched to branch 'xx'
[14:28:47][DEBUG] git clean -ffdx
[14:28:47][DEBUG] Running 'git clean -ffdx' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[14:28:47][DEBUG] git submodule foreach --recursive git clean -ffdx
[14:28:47][DEBUG] Running 'git submodule foreach --recursive git clean -ffdx' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[14:28:47][DEBUG] git reset --hard
[14:28:47][DEBUG] Running 'git reset --hard' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
HEAD is now at e28e5cb runtimeobject.lib should be lower case
[14:28:47][DEBUG] git submodule foreach --recursive git reset --hard
[14:28:47][DEBUG] Running 'git submodule foreach --recursive git reset --hard' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[14:28:47][DEBUG] git submodule update --init --recursive
[14:28:47][DEBUG] Running 'git submodule update --init --recursive' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[14:28:47][DEBUG] Applying patch 'opencl/0001-OpenCL-git-prefix.patch' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[14:28:47][INFO] Copying patch from '/home/u/Desktop/_working/patches/opencl/0001-OpenCL-git-prefix.patch' to '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git/0001-OpenCL-git-prefix.patch'
[14:28:47][DEBUG] cp -f "/home/u/Desktop/_working/patches/opencl/0001-OpenCL-git-prefix.patch" "/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git/0001-OpenCL-git-prefix.patch" # copy file 
[14:28:47][INFO] Patching source using: '0001-OpenCL-git-prefix.patch'
[14:28:47][DEBUG] patch -p1 < "0001-OpenCL-git-prefix.patch"
[14:28:47][DEBUG] Running 'patch -p1 < "0001-OpenCL-git-prefix.patch"' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
patching file CMakeLists.txt
Hunk #1 succeeded at 78 with fuzz 1 (offset 3 lines).
[14:28:47][DEBUG] Applying patch 'opencl/0002-OpenCL-git-header.patch' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[14:28:47][INFO] Copying patch from '/home/u/Desktop/_working/patches/opencl/0002-OpenCL-git-header.patch' to '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git/0002-OpenCL-git-header.patch'
[14:28:47][DEBUG] cp -f "/home/u/Desktop/_working/patches/opencl/0002-OpenCL-git-header.patch" "/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git/0002-OpenCL-git-header.patch" # copy file 
[14:28:47][INFO] Patching source using: '0002-OpenCL-git-header.patch'
[14:28:47][DEBUG] patch -p1 < "0002-OpenCL-git-header.patch"
[14:28:47][DEBUG] Running 'patch -p1 < "0002-OpenCL-git-header.patch"' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
patching file loader/windows/icd_windows_hkr.h
[14:28:47][INFO] Running run_post_regexreplace-command: 'sed -i.bak 's/Windows.h/windows.h/' ./loader/windows/icd_windows_envvars.c'
[14:28:47][DEBUG] Running 'sed -i.bak 's/Windows.h/windows.h/' ./loader/windows/icd_windows_envvars.c' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[14:28:47][INFO] C-Making 'opencl_icd' with: . -DCMAKE_TOOLCHAIN_FILE="/home/u/Desktop/_working/workdir/mingw_toolchain.cmake" -G"Ninja" -DCMAKE_INSTALL_PREFIX=/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DOPENCL_ICD_LOADER_REQUIRE_WDK=OFF -DOPENCL_ICD_LOADER_DISABLE_OPENCLON12=ON 
[14:28:47][DEBUG] cmake . -DCMAKE_TOOLCHAIN_FILE="/home/u/Desktop/_working/workdir/mingw_toolchain.cmake" -G"Ninja" -DCMAKE_INSTALL_PREFIX=/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DOPENCL_ICD_LOADER_REQUIRE_WDK=OFF -DOPENCL_ICD_LOADER_DISABLE_OPENCLON12=ON 
[14:28:47][DEBUG] Running 'cmake . -DCMAKE_TOOLCHAIN_FILE="/home/u/Desktop/_working/workdir/mingw_toolchain.cmake" -G"Ninja" -DCMAKE_INSTALL_PREFIX=/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DOPENCL_ICD_LOADER_REQUIRE_WDK=OFF -DOPENCL_ICD_LOADER_DISABLE_OPENCLON12=ON ' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
-- The C compiler identification is GNU 10.0.1
-- The CXX compiler identification is GNU 10.0.1
-- Check for working C compiler: /home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-gcc
-- Check for working C compiler: /home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-g++
-- Check for working CXX compiler: /home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Looking for secure_getenv
-- Looking for secure_getenv - not found
-- Looking for __secure_getenv
-- Looking for __secure_getenv - not found
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    OPENCL_ICD_LOADER_REQUIRE_WDK


-- Build files have been written to: /home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git
[14:28:48][DEBUG] make clean
[14:28:48][DEBUG] Running 'make clean' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
make: *** No rule to make target 'clean'.  Stop.
[14:28:48][INFO][NINJA] Building 'opencl_icd' with 'build_options':  in /home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git
[14:28:48][DEBUG] ninja -j 4 
[14:28:48][DEBUG] Running 'ninja -j 4 ' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
[1/9] Building C object CMakeFiles/OpenCL.dir/loader/windows/icd_windows_dxgk.c.obj
[2/9] Building C object CMakeFiles/OpenCL.dir/loader/windows/icd_windows.c.obj
In file included from loader/windows/icd_windows.c:21:
loader/windows/icd_windows_hkr.h:40:19: warning: 'DEVPKEY_Device_ClassGuid' initialized and declared 'extern'
   40 | DEFINE_DEVPROPKEY(DEVPKEY_Device_ClassGuid,              0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 10);    // DEVPROP_TYPE_GUID
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~
loader/windows/icd_windows_hkr.h:38:126: note: in definition of macro 'DEFINE_DEVPROPKEY'
   38 | #define DEFINE_DEVPROPKEY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8, pid) extern const DEVPROPKEY_2 DECLSPEC_SELECTANY name = { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }, pid }
      |                                                                                                                              ^~~~
loader/windows/icd_windows.c: In function 'khrIcdOsVendorsEnumerate':
loader/windows/icd_windows.c:195:64: warning: passing argument 2 of 'pCreateDXGIFactory' from incompatible pointer type [-Wincompatible-pointer-types]
  195 |             HRESULT hr = pCreateDXGIFactory(&IID_IDXGIFactory, &pFactory);
      |                                                                ^~~~~~~~~
      |                                                                |
      |                                                                IDXGIFactory **
loader/windows/icd_windows.c:195:64: note: expected 'void **' but argument is of type 'IDXGIFactory **'
loader/windows/icd_windows.c: In function 'khrIcdOsVendorsEnumerateOnce':
loader/windows/icd_windows.c:247:5: warning: implicit declaration of function 'InitOnceExecuteOnce' [-Wimplicit-function-declaration]
  247 |     InitOnceExecuteOnce(&initialized, khrIcdOsVendorsEnumerate, NULL, NULL);
      |     ^~~~~~~~~~~~~~~~~~~
[3/9] Building C object CMakeFiles/OpenCL.dir/loader/icd.c.obj
[4/9] Building C object CMakeFiles/OpenCL.dir/loader/windows/icd_windows_envvars.c.obj
[5/9] Building RC object CMakeFiles/OpenCL.dir/loader/windows/OpenCL.rc.res
[6/9] Building C object CMakeFiles/OpenCL.dir/loader/windows/icd_windows_hkr.c.obj
In file included from loader/windows/icd_windows_hkr.c:20:
loader/windows/icd_windows_hkr.h:40:19: warning: 'DEVPKEY_Device_ClassGuid' initialized and declared 'extern'
   40 | DEFINE_DEVPROPKEY(DEVPKEY_Device_ClassGuid,              0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 10);    // DEVPROP_TYPE_GUID
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~
loader/windows/icd_windows_hkr.h:38:126: note: in definition of macro 'DEFINE_DEVPROPKEY'
   38 | #define DEFINE_DEVPROPKEY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8, pid) extern const DEVPROPKEY_2 DECLSPEC_SELECTANY name = { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }, pid }
      |                                                                                                                              ^~~~
loader/windows/icd_windows_hkr.c: In function 'khrIcdOsVendorsEnumerateHKR':
loader/windows/icd_windows_hkr.c:343:21: warning: passing argument 2 of 'CM_Get_DevNode_PropertyW' from incompatible pointer type [-Wincompatible-pointer-types]
  343 |                     &DEVPKEY_Device_ClassGuid,
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                     |
      |                     const DEVPROPKEY_2 * {aka const struct _DEVPROPKEY_2 *}
In file included from loader/windows/icd_windows_hkr.c:23:
/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/include/cfgmgr32.h:840:88: note: expected 'const DEVPROPKEY *' but argument is of type 'const DEVPROPKEY_2 *' {aka 'const struct _DEVPROPKEY_2 *'}
  840 |   CMAPI CONFIGRET WINAPI CM_Get_DevNode_PropertyW(DEVINST dnDevInst, const DEVPROPKEY *PropertyKey, DEVPROPTYPE *PropertyType, PBYTE PropertyBuffer, PULONG PropertyBufferSize, ULONG ulFlags);
      |                                                                      ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
[7/9] Building C object CMakeFiles/OpenCL.dir/loader/icd_dispatch.c.obj
[8/9] Building CXX object CMakeFiles/OpenCL.dir/loader/windows/icd_windows_apppackage.cpp.obj
[9/9] Linking CXX shared library OpenCL.dll
[14:28:51][INFO] Running post-build-command: 'cp -vf "libOpenCL.dll.a" "/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32/lib/libOpenCL.dll.a"'
[14:28:51][DEBUG] cp -vf "libOpenCL.dll.a" "/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32/lib/libOpenCL.dll.a"
[14:28:51][DEBUG] Running 'cp -vf "libOpenCL.dll.a" "/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32/lib/libOpenCL.dll.a"' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
'libOpenCL.dll.a' -> '/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32/lib/libOpenCL.dll.a'
[14:28:51][INFO] Running post-build-command: 'cp -vf "libOpenCL.dll.a" "/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32/lib/libOpenCL.a"'
[14:28:51][DEBUG] cp -vf "libOpenCL.dll.a" "/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32/lib/libOpenCL.a"
[14:28:51][DEBUG] Running 'cp -vf "libOpenCL.dll.a" "/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32/lib/libOpenCL.a"' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
'libOpenCL.dll.a' -> '/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32/lib/libOpenCL.a'
[14:28:51][INFO] Running post-build-command: 'if [ ! -f "already_ran_make_install" ] ; then touch already_ran_make_install ; fi'
[14:28:51][DEBUG] if [ ! -f "already_ran_make_install" ] ; then touch already_ran_make_install ; fi
[14:28:51][DEBUG] Running 'if [ ! -f "already_ran_make_install" ] ; then touch already_ran_make_install ; fi' in '/home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git'
Changing dir from /home/u/Desktop/_working/workdir/x86_64/OpenCL-ICD-Loader_git to ..
[14:28:51][DEBUG] cd ..
[14:28:51][INFO] Building dependency 'opencl_icd': Done!

@rcombs
Copy link

rcombs commented Jun 4, 2020

I'm a little bit confused about this. I was under the impression that it was safe for applications that want to use OpenCL to ship their own build of the loader (in order to not depend on one being installed on the system), and use it to load ICDs if present. But in this issue, it's being discussed as if applications need to depend on the system-installed loader. Is a copy of the loader guaranteed to be present on all Windows systems (thus making it safe to have a hard runtime dependency on that)? If not, do I need to implement an "ICD loader loader" to dynamically load the OS-installed loader at runtime and call into that?

@hydra3333
Copy link
Author

hydra3333 commented Jun 4, 2020

ship their own build of the loader (in order to not depend on one being installed on the system), and use it to load ICDs if present.

Isn't that dangerous ? Overwriting/bypassing what manufacturers/windows may have installed ?

Is a copy of the loader guaranteed to be present on all Windows systems (thus making it safe to have a hard runtime dependency on that)?

Not that I've found.

To be over-ridden by the owners here of course.

@rcombs
Copy link

rcombs commented Jun 4, 2020

I was under the impression that the loader was supposed to be an implementation of a standard interface, and that implementations were supposed to be fairly fungible, with all the device-specific stuff being in the ICD itself. If that's not the case, then… what's the point of the loader as a separate library?

@MathiasMagnus
Copy link
Contributor

MathiasMagnus commented Jun 4, 2020

then… what's the point of the loader as a separate library?

You need the ICD loader to enable multiple implementations living happily side-by-side in a plug'n'play manner.

Isn't that dangerous ? Overwriting/bypassing what manufacturers/windows may have installed ?

It is discouraged because ISVs typically fire and forget and don't do a great job of keeping all their dependencies up to date, not to mention I may install ffmpeg once and leave it at the same version for an entire year. Even if the project did a good job of updating its deps, I may not opt-in for those updates, and implementations may go ahead and update their ICD, but the bundled loader of ffmpeg for eg. may thus be out of sync.

Ultimately it all boils down to who owns the loader: is it a system component? Is it part of the driver? The current status quo is that it's shared between all vendors shipping ICDs. They make an honest coorinated effort in not screwing up each others ICD by shipping incompatible loaders.

Bypassing the system loader is a bad idea, because projects will likely target building a minimal loader (just make it work), but the additions to loading OpenCLOn12 are opt-in, but in any case an option. Even if I install OpenCLOn12 on my system, if projects choose to bypass the system installed loader, they may not be able to load some implementations, CLOn12 being a prime candidate as it requires extra, novel footwork from the loader.

Windows library model incentivies people to bundle their loader, because they need to build it to obtain an import lib, but don't ship libraries / projects that bundle the loader. You essentially commit to updating your product on every channel on the same day a driver comes out from any vendor. It's calling for trouble. In development scenarios it's totally okay to statically link a loader, because "works on my machine" is legit on dev boxes. But don't ship stuff like that.

@jenatali
Copy link
Contributor

jenatali commented Jun 4, 2020

Adding my two cents as a Windows developer: We bend over backwards to make old apps run on new versions of Windows.

If old apps have a dependency on a system OpenCL loader, that means that we're responsible for ensuring that the system loader can find an OpenCL ICD to make the app work. It may mean changes to the ICD loader as the platform evolves, or potentially new changes to find new kinds of ICDs, as is the case for CLOn12.

If old apps ship the ICD loader, that means their dependency on the system has changed. Instead of "looking for an ICD" being the operative request to the system, "looking for regkeys" or "querying the kernel" becomes the interface that must remain working. It severely restricts our options for evolving the platform, and makes development/deployment of things like CLOn12 more complex.

Something like the ICD loader belongs as a system component. In future versions of Windows, we will start guaranteeing that an up-to-date version of the ICD loader comes included in the OS installation, so that apps can feel more comfortable taking a dependency on it being present.

Regarding needing a "loader loader," the cheap option is to just use delay-load linking. The rest of your code doesn't need to care, and then if the loader isn't present, or doesn't have the right entrypoints, you can gracefully handle that case. Though if you want to work with old loaders as well as new loaders, yes you'd need to dynamically retrieve your individual entrypoints from the loader, since on Windows, linking (normal or delay-load) is all-or-nothing.

@rcombs
Copy link

rcombs commented Jun 4, 2020

Thanks @jenatali, I really appreciate the perspective.
That said, I'm still kind of taken aback at the API stability situation here, which isn't what I expected, isn't what anyone else working on OpenCL code for ffmpeg seems to have expected, and isn't what's sort of implied by the existence of this package. As far as I can tell, there are 3 major scenarios:

  • macOS, where the relevant API is exposed as an OS component I can link directly to with no concerns
  • Linux and FreeBSD, where there are no guarantees about the availability of the loader or any particular ICD, but the interface the loader uses to find and load ICDs is frozen(?), so it's safe to include as part of an application
  • Windows, where there are no guarantees about the availability of the loader and the interface the loader uses to find and load the ICDs changes over time

On Linux and FreeBSD, that means this package serves a clear purpose: you can bundle it in your package, or add it as a dependency in package managers, to use OpenCL without having a hard dependency on any actual ICD being installed. Excellent.

On Windows, it sounds like in the future we'll be in a position similar to that of macOS, where I can just link to the OS-installed copy, but until that ships (and until I stop having to support older Windows versions where it hasn't, which likely won't be for years), that's not an option. So this package existing seemed to imply that it was safe to bundle with an application. If that's not the case, it should be made clear in the README file that nobody trying to ship a userspace application should actually be building this or linking against it.

Delay-load linking isn't available in gcc or clang on windows as far as I'm aware, so that's not an option here… so I guess I'm going to have to restructure ffmpeg's OpenCL filtering code to load OpenCL.dll at runtime and call into it. This will probably look something like ffnvcodec, and require maintaining what's essentially a parallel set of OpenCL headers that declare function pointers instead of actual functions. Up to now we'd sort of assumed that wasn't necessary, again because it appeared that this package was supposed to serve that purpose. So… I guess that's what I'll have to do, I'm just kinda frustrated that it's necessary.

@jenatali
Copy link
Contributor

jenatali commented Jun 4, 2020

My understanding of the reason this project exists for Windows is to provide a common source for drivers to be able to include this DLL in their driver packages. I was shocked to learn that static linking was possible, or that apps could/do include this as part of the app.

On Windows, if you have an OpenCL driver, you have a system OpenCL ICD loader. In the future that will be even more broad, to just "you have an OpenCL ICD loader." However, if OpenCL is optional for you, the lack of an ICD loader could prevent you from loading, unless you use dynamic linking or delay loading.

Regarding delay-load support, the LLVM linker does support it: https://github.com/llvm/llvm-project/blob/3508c1d8fbe9b053d32330b6995c88c57a82e33f/lld/COFF/Driver.cpp#L1786 . I'm not sure about MinGW/GCC.

I've also heard that there's interest in providing a different way of linking to OpenCL, which @bashbaug has been looking into, which would handle dynamically loading the loader and dispatching to ICDs efficiently.

@rcombs
Copy link

rcombs commented Jun 4, 2020

My understanding of the reason this project exists for Windows is to provide a common source for drivers to be able to include this DLL in their driver packages.

Which raises the question of why it was ever part of driver packages (instead of installed with the system) to begin with, but I suppose that's immaterial now.

I was shocked to learn that static linking was possible, or that apps could/do include this as part of the app.

You can see why it'd seem like the right thing to do, given what it allows and how the documentation doesn't tell you not to, right? I'd really like to get things clarified here, so app developers can know how they're meant to interact with this instead of just guessing.

Re: guarantees, yeah, OpenCL's optional in my use-case (and probably for most people who ship ffmpeg, whether it's as a standalone static build of the CLI tools or as part of a larger application).

Re: lld, ooh, thanks! I couldn't find it in their docs so I assumed it didn't exist; should've known there's be undocumented features like that.

Definitely interested in what @bashbaug's up to; if we can use that in ffmpeg instead of coming up with something custom, I'm all for it.

@bashbaug
Copy link
Contributor

bashbaug commented Jun 8, 2020

Hello! Thanks for (re-)looping me into this discussion.

A POC demonstrating what I've been up to is here. It's (probably) not quite ready for prime time yet, but it is working for my simple test cases:

https://github.com/bashbaug/SimpleOpenCLSamples/tree/hybrid-loader-lib/libOpenCLHybrid

The basic idea it is to link with this library and not to the ICD loader directly. This library will dynamically load the system ICD loader (or fail gracefully, if it's not found), but only call into the system ICD loader for platform enumeration. All of the other OpenCL APIs are implemented directly within the library itself and linked statically.

The nice thing about this approach is that it doesn't bypass the system ICD loader completely, so applications will use the latest mechanisms to enumerate ICDs, but otherwise there are no dependencies on the ICD loader.

If this sounds interesting I'll at least move it into its own git repo to make it easier to find. Thanks!

@rcombs
Copy link

rcombs commented Jun 8, 2020

This sounds exactly like the solution to this problem I've been looking for! I'd love to see it in its own repo, and potentially linked from the readme here as a "if you're distributing an application this is probably what you want".

@rcombs
Copy link

rcombs commented Jun 8, 2020

Hmmmm, looking closer at the implementation, though… is it actually guaranteed that the layout of the vtable in the loader won't change? And that the copy of the loader installed on the system will use the same layout as the official loader?

@jenatali
Copy link
Contributor

jenatali commented Jun 8, 2020

That layout is prescribed in the cl_khr_icd extension. Personally I agree that there should be more runtime negotiation of table layout, but yes that is the layout that all ICDs use.

@bashbaug
Copy link
Contributor

I know this is a very old thread, but I think we finally fixed the last of the mingw issues. 🎉

@hydra3333 if you're still around would you mind confirming that the latest changes work for you so we can close this issue? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants