Re: [CMake] Problems building a MODULE library (OpenFX plugin) with correct cuda object linking

2017-01-13 Thread Robert Maynard
Hi,

Here is a example that uses CUDA_WRAP_SRCS and separable compilation.
I quickly ported the code from a project, so it most likely has some
minor issues.

https://git.io/vMga3

On Thu, Jan 12, 2017 at 5:04 PM, Ingmar Rieger  wrote:
> Hey,
>
> thank you for your answer. I already tried with CUDA_WRAP_SRCS but didn't
> really get how to use it and the
> https://cmake.org/cmake/help/v3.7/module/FindCUDA.html lacks of any samples
> really showing what is going on. How can I use CUDA_WRAP_SRCS to create the
> OBJECT and then add it to a library? add_library also only supports source
> files (Cannot find source file error when trying to add an object).
>
> Is there an example anywhere that demonstrates how to manually add a CUDA
> object there?
>
>
> On 2017-01-11 21:42, Robert Maynard wrote:
>>
>> I believe you will want to use the low level command CUDA_WRAP_SRCS
>> with the MODULE option. Since CUDA_WRAP_SRCS is a low level command,
>> If you need separable compilation you will need to manually invoke
>> those steps too ( read CUDA_SEPARABLE_COMPILATION documentation on
>> what methods you will need to use ).
>
>
>
> --
> Regards,
> Ingmar
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake


Re: [CMake] Problems building a MODULE library (OpenFX plugin) with correct cuda object linking

2017-01-13 Thread Ingmar Rieger

Hey,

thank you for your answer. I already tried with CUDA_WRAP_SRCS but 
didn't really get how to use it and the 
https://cmake.org/cmake/help/v3.7/module/FindCUDA.html lacks of any 
samples really showing what is going on. How can I use CUDA_WRAP_SRCS to 
create the OBJECT and then add it to a library? add_library also only 
supports source files (Cannot find source file error when trying to add 
an object).


Is there an example anywhere that demonstrates how to manually add a 
CUDA object there?


On 2017-01-11 21:42, Robert Maynard wrote:

I believe you will want to use the low level command CUDA_WRAP_SRCS
with the MODULE option. Since CUDA_WRAP_SRCS is a low level command,
If you need separable compilation you will need to manually invoke
those steps too ( read CUDA_SEPARABLE_COMPILATION documentation on
what methods you will need to use ).



--
Regards,
Ingmar
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake


Re: [CMake] Problems building a MODULE library (OpenFX plugin) with correct cuda object linking

2017-01-11 Thread Robert Maynard
I believe you will want to use the low level command CUDA_WRAP_SRCS
with the MODULE option. Since CUDA_WRAP_SRCS is a low level command,
If you need separable compilation you will need to manually invoke
those steps too ( read CUDA_SEPARABLE_COMPILATION documentation on
what methods you will need to use ).

On Tue, Jan 10, 2017 at 1:30 PM,   wrote:
> Hello,
>
> after hours and hours of searching and trying to get it to work I hope
> someone here can help me as I'm now out of ideas. I'm trying to build an
> OpenFX plugin for DaVinci Resolve (a movie color grading software,
> https://www.blackmagicdesign.com/products) via CMake. Resolve is delivered
> with a developer sample plugin using a standard Makefile (Mac) and project
> files for Apple XCode/VisualStudio. But for a better structure I wanted to
> build a CMake build framework for this plugin.
>
> Notes for better understanding: The CUDA implementation is a proprietary Add
> On to the OpenSource OpenFX interfaces as far as I understand it. Stock
> OpenFX would pass memory references only to host memory address space while
> the Resolve extension passed CUDA/OpenCL addresses to reduce memory transfer
> overhead for better real time processing. OpenFX plugins are build as
> bundles of objects(?) (MODULE library build in CMake).
>
> The basic structure is a plugin that offers processing with CPU, OpenCL or
> CUDA depending on the processing mode the host application is using. This
> plugin is bundled into a single module library which is loaded by Resolve.
> For the plugin a few helper classes are used to handle the Plugin metadata
> (user interface, host communication) while CUDA/OpenCL control code is also
> seperated into two separate files (OpenCLKernel.cpp and CudaKernel.cu). Both
> contain the GPU Kernel itselt and a host function which is included in the
> main Plugin just via extern declaration. Sample:
>>
>> extern void RunCudaKernel(int p_Width, int p_Height, float* p_Gain, const
>> float* p_Input, float* p_Output);
>
>
> The Makefile then just compiles all cpp files with the standard $(CXX)
> compiler and the CudaKernel.cu with $(NVCC) which is defined before. Then a
> simple
>>
>> $(CXX) -bundle $^ -o $@ -L${CUDAPATH}/lib -lcuda -lcudart
>> -F/Library/Frameworks -framework CUDA -framework OpenCL
>
> does the linking and works fine.
>
>
> I tried to replicate this structure of linking in CMake and it works as long
> as I keep CUDA deactivated (One of the reasons of building a flexible CMake
> infrastructure is making a few parts configurable via CMake/Compiler
> options). Most stuff is working now, but I have a problem integrating the
> CUDA part.
>
> For OpenCL I just build an object library from the OpenCLKernel.cpp and add
> it as a target object:
>>
>> add_library(GainLibOpenCL OBJECT OpenCLKernel.cpp)
>
> ...
>>
>> add_library(${PLUGIN_NAME} MODULE src/${PLUGIN_NAME}.cpp
>> $)
>
>
> I tried to replicate this for the CUDA code but cuda_add_library doesn't
> seem to support generating object files and a combination of cuda_compile +
> add_library also doesn't allow to generate object files so how do I
> replicate the Makefile result.
>
> Here are two examples how I tried different methods. Did a few more tests
> based on many results of questions on the net but non solved my problem.
>
> Variant 1:
>>
>>  cuda_add_library(GainLibCUDA CudaKernel.cu)
>>  set(LIBS ${LIBS} GainLibCUDA PARENT_SCOPE)
>
> Will compile but result in a crash of Resolve, with STATIC as an option for
> cuda_add_library it builds and Resolve stays open, but processing isn't
> working. And it links to the CUDA static libraries which isn't intended as
> the host cuda lib should be used.
>
>>  cuda_compile(cuda_exec_obj CudaKernel.cu)
>>  add_library(GainLibCUDA OBJECT CudaKernel.h ${cuda_exec_obj})
>>  set(TARGET_OBJECTS ${TARGET_OBJECTS} $
>> PARENT_SCOPE)
>
>
> Results in the error:
>>
>> CMake Error at src/CUDA/CMakeLists.txt:21 (add_library):
>>   OBJECT library "GainLibCUDA" contains:
>>
>> cuda_compile_1_generated_CudaKernel.cu.o
>>
>>   but may contain only sources that compile, header files, and other files
>>   that would not affect linking of a normal library.
>
>
> Also just adding "cuda_compile(cuda_exec_obj CudaKernel.cu)" and then
> ${cuda_exec_obj} as a file to the "add_library(${PLUGIN_NAME} MODULE ..."
> line results in and error: "Cannot find source file".
>
> So this mail got pretty long but I hope this helps someone to help me and
> then also help others if they reach a similar problem.
>
>
> Kind regards,
> Ingmar
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/train