AcademySoftwareFoundation / openfx

OpenFX effects API
Other
393 stars 119 forks source link

update install instrution and package opencl #148

Closed janimatic closed 3 months ago

janimatic commented 3 months ago

Hello, I am using vs2019 under windows10 x64 with gpu-gain-example branch to test opencl image vs opencl buffer.

The README.md should be updated with conan version

I had success with conan<2, but Gary mentioned conan v 2 (2.0.1?) is working for him. following https://github.com/AcademySoftwareFoundation/openfx/pull/113 and the current README.md instructions

>Traceback (most recent call last):
>  File "c:\python37\lib\site-packages\conan\cli\cli.py", line 268, in main [...]
> conan TypeError: __new__() takes 5 positional arguments but 6 were given

*  with "conan<2.0.0" (conan 1.63.0)

pip install --force-reinstall -v "conan<2.0.0" conan install -s build_type=Release --build=missing . cmake --build build/Release --config Release cmake --build build --config Release

>   OpenCLKernel.cpp
> P:\workflow\dev\janimatic\openfx\Support\Plugins\GPUGain\OpenCLKernel.cpp(15,10): fatal error C1083: Impossible d'ouvrir le fichier include : 'CL/cl.h' : No such file or directory [P:\workflow\dev\janimatic\openfx\build\Support\Plugins\example-GPUGain-support.vcxproj]

### In gpu-gain-example branch, opencl is not packaged by conan/cmake

conanfile.py doesn't add opencl-icd-loader & opencl-headers packages to [require]
Support/Plugins/CMakeLists.txt doesn't include/link opencl if OFX_SUPPORTS_OPENCLRENDER=TRUE and not APPLE
I've successully build gpu-gain-example branch with opencl (and successully tested under resolve with opencl in gpu preferences) by editing Support/Plugins/CMakeLists.txt and using OpenCL-SDK headers and libs

* WIP workaround :

I have builded and copy pasted includes/libs from OpenCL-SDK, and edited Support/Plugins/CMakeLists.txt  as follow

if(WIN32) if (OFX_SUPPORTS_OPENCLRENDER) set(OpenCL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/OpenCL/include) set(OpenCL_LIBRARY ${PROJECT_SOURCE_DIR}/OpenCL/lib/x86_64/OpenCL.lib)

find_package(OpenCL REQUIRED)

endif()

endif()

foreach(PLUGIN IN LISTS PLUGINS) [...] elseif(WIN32) if (OFX_SUPPORTS_OPENCLRENDER) target_include_directories(${TGT} PUBLIC "${OpenCL_INCLUDE_DIR}") target_link_libraries(${TGT} "${OpenCL_LIBRARY}") endif() else() endif() endforeach()

I successully tested example-GPUGain-support.ofx under resolve, with opencl forced in gpu preferences

* suggested:
No opencl files in openfx repo of course,
but use OpenCL conan packaging by editing conanfile.py and use
https://conan.io/center/recipes/opencl-icd-loader 
https://conan.io/center/recipes/opencl-headers

### include opencl.hpp in openfx/Support/Plugins/GPUGain/OpenCLKernel.cpp
Is it intentional that you don't use[ the latest opencl hpp](https://github.com/KhronosGroup/OpenCL-CLHPP/releases/tag/v2.0.9) ?
Those let people switch to any opencl version easily.

ifdef APPLE

include <OpenCL/cl.h>

else

//#include <CL/cl.h> //#define CL_HPP_TARGET_OPENCL_VERSION 200

include <CL/opencl.hpp>

endif



Thanks for your great work!
Julien
garyo commented 3 months ago

I'm currently using conan 2.1.0, and cmake 3.28.1 on Windows (and python 3.12.1). A clean build of the current main branch (60262ef) works for me in that case, using scripts/build.sh. Does that (latest) version of conan work for you? If so, I'll update the README.

I have not tried building OpenCL on Windows though. I'll try your suggestions.

Please note that the gpu-gain-example branch has now been merged into main, so please test on main.

garyo commented 3 months ago

Glad it's working now! I think if you want OpenCL support you also have to add "-DOFX_SUPPORTS_OPENCLRENDER" to your cmake line; see scripts/build-cmake.sh.

Also, Is your last note about hpp headers something we should include in our GPUGain sample? I'm not all that familiar with OpenCL.

janimatic commented 3 months ago

I confirm that "conan>=2.1.0" is working perfectly I had to manually remove conan's cache, and create a default profile (with conan profile detect) :

rmdir /s /q %userprofile%\.conan
rmdir /s /q %userprofile%\.conan2
pip install --force-reinstall -v "conan>=2.1.0"
conan --version
conan profile detect

In the main branch :

conan install -s build_type=Release --build=missing .
cmake --build build --config Release

In the opencl branch :

conan install -s build_type=Release --build=missing . -o use_opencl=True
cmake --build build --config Release

It builds fine.

I could switch to hpp headers and choose opencl version

//#include <CL/cl.h>
#define CL_HPP_TARGET_OPENCL_VERSION 200
#include <CL/opencl.hpp>

Thanks! (sorry for my cross posting mess...)

janimatic commented 3 months ago

Also, Is your last note about hpp headers something we should include in our GPUGain sample? I'm not all that familiar with OpenCL.

yes i think you can safely replace the include by hpp as it works with the current opencl packages. That might be handy to be able to switch opencl version, with some drivers.

janimatic commented 3 months ago

I just noticed that, when switching to hpp, opencl2.0 is the minimum though, # define CL_HPP_MINIMUM_OPENCL_VERSION 200 I am not sure if that's the case with cl.h https://stackoverflow.com/questions/40613243/cant-run-any-available-opencl-sample-with-recent-api-cl-cl2-hpp

EDIT: sorry for the confusion, actually you can go lower, if some driver needs it :

#define CL_HPP_MINIMUM_OPENCL_VERSION 120
#define CL_HPP_TARGET_OPENCL_VERSION 120
janimatic commented 3 months ago

Hello @garyo and everyone, Do you have any guideline about creating cmake based project from scratch, linking OpenFx ? Is it recommended to use cmake's FetchContent with conan at all ? Or do you have some dev releases packages that could be later easily integrated in github workflow actions ? (for the moment, i've just worked in the plugin folder of my openfx fork to avoid those questions...) Thanks ! Best regard Julien

janimatic commented 3 months ago

ps : using openfx as a git submodule was much easier, thanks anyway...

garyo commented 3 months ago

Git submodule is what some other folks are doing too; that should work fine. I am hoping to package up the conan recipe to put on conancenter soon; that should make it even easier to work with. I would love any help with that.

BTW, this isn't OpenFX-specific (yet!), but I did create a simple CMake+Conan plugin build template at https://github.com/garyo/cmake-conan-plugin-template -- you might find it useful.

garyo commented 3 months ago

This is now merged in as #149