sctincman / freeocl

OpenCL 1.2 implementation targeting CPUs, utilizing an external C++ compiler
GNU Lesser General Public License v3.0
0 stars 0 forks source link

compile freeocl for mingw #14

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. We want to use freeocl for our project to be able to distribute a 
libOpenCL.so for Linux and libOpenCL.dll for windows as well.
I understand that the project does currently not officially support windows, 
but I guess you are working on it. I managed to modify the sources, so that it 
can at least compile the libOpenCL.dll
for this, it is necessary to use the https://code.google.com/p/dlfcn-win32/ 
project, which provides a dlfcn implementation for windows
This needs to be compiled with the submitted patch:
https://code.google.com/p/dlfcn-win32/issues/detail?id=12
this exports the function declarations with C-naming, so that it can be linked
2.
cmake considers dll's as runtime, so the INSTALL directives need to be 
complemented by a "RUNTIME DESTINATION bin" or whatever is desired
3.
Now, using an mingw cross-compiler (created by mxe.cc) the project can be 
configured in the build directory:
cmake -DCMAKE_TOOLCHAIN_FILE=../i686-w64-mingw32.cmake 
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INCLUDE_PATH=../dlfcn/ 
-DCMAKE_LIBRARY_PATH=../dlfcn/ ../
considereing that the attached patch is applied and dlfcn was compiled within 
the project folder, so that the dlfcn.h can be found and libdl.a can be found 
(using the included FindLibdl.cmake module).

What is the expected output? What do you see instead?
make OpenCL
will now complain about some small errors:
src/icd/icd_api.cpp:560:26: error: declaration of C function 'cl_int 
clEnqueueNativeKernel(cl_command_queue, void (*)(void*), void*, size_t, 
cl_uint, _cl_mem* const*, const void**, cl_uint, _cl_event* const*, 
_cl_event**)' conflicts with
           cl_event *event)
                          ^
In file included from src/dispatch.h:24:0,
                 from src/freeocl.h:26,
                 from src/icd/icd_api.cpp:18:
include/CL/cl.h:1132:1: error: previous declaration 'cl_int 
clEnqueueNativeKernel(cl_command_queue, void (__attribute__((__stdcall__)) 
*)(void*), void*, size_t, cl_uint, _cl_mem* const*, const void**, cl_uint, 
_cl_event* const*, _cl_event**)' here
 clEnqueueNativeKernel(cl_command_queue  /* command_queue */,

This is because the function declaration within the source is missing the 
"CL_CALLBACK" for the callback function pointer as it is actually defined in 
the cl.h (also corrected in the attached patch). Adding it to src/dispatch.h 
and src/icd/icd_api.cpp fixes it.

The last problem is the following:
In file included from src/icd/icd_api.cpp:25:0:
src/kernel.h:24:22: fatal error: ucontext.h: No such file or directory
 #include <ucontext.h>

This is because windows and mingw does not have a ucontext implementation (not 
POSIX?!) - there is an implementation available, it seems to compile:
http://www.codeproject.com/Articles/4225/Unix-ucontext_t-Operations-on-Windows-P
latforms
and can be used, but I am not sure if this is desired.

But I think for compiling the libOpenCL.dll it should not be necessary to have 
the kernel.h include a declaration for __FCL_setwg which uses the ucontext. But 
I am not familiar with the layout of the freeocl project, so I am not able to 
deconvolute the kernel.h - but the attached patch currently comments the 
ucontext.h include and the __FCL_setwg declaration, since it is not required by 
libOpenCL.dll

With that, libOpenCL.dll is compiling with the cross compiler. The Freeocl is 
another issue that can only be solved if the ucontext issue is adressed..

What version of the product are you using? On what operating system?
freeocl r319 on Ubuntu 12.04 using mxe mingw cross compiler gcc 4.8.1
dlfcn-win32 r19 with patch )as mentioned above)

Please provide any additional information below.
I am looking forward to your feedback

Original issue reported on code.google.com by nilswoet...@gmail.com on 2 Dec 2013 at 5:13

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the patch.

The ICD library has a slightly different behavior on windows (it uses the 
registry instead of files) so porting it requires a bit more work. However 
you're right the libOpenCL.dll doesn't need __FCL_setwg which is required only 
by the internal threads/fibers scheduler.

I may have a use for a windows port too so I am going to have a closer look at 
it.

Original comment by roland.b...@polytechnique.org on 12 Dec 2013 at 10:50

GoogleCodeExporter commented 9 years ago
I have been working on porting FreeOCL to MinGW64, it still has a few rough 
edges but I can run the clbuiltins sample successfully :).

Feel free to test it and report issues ;).

NB: you'll have to play with FREEOCL_CXX_FLAGS or copy FreeOCL's stdlib files 
to your MinGW64 install in order to build kernels. Building libatomic_ops is 
also required.

Original comment by zuzu...@gmail.com on 18 May 2014 at 8:47