32 Replies Latest reply on Jan 5, 2010 9:26 AM by genaganna

    OpenCL with GCC

    koveras
      Trying to compile OpenCL with GCC

      Hi!

      I'm trying to compile OpenCL programs with gcc compiler in Windows XP and when I run it, I get unexpected results. The programs are OK because I've tried on Visual Studio and it works.

      Does AMD give support to gcc on Windows on the beta4?

      If not, is it planned to give it support on the final release?

      I need to compile it with gcc, so I'm really interested on it

      Thanks a lot

        • OpenCL with GCC
          genaganna

           

          Originally posted by: koveras Hi!

           

          I'm trying to compile OpenCL programs with gcc compiler in Windows XP and when I run it, I get unexpected results. The programs are OK because I've tried on Visual Studio and it works.

           

          Does AMD give support to gcc on Windows on the beta4?

           

          If not, is it planned to give it support on the final release?

           

          I need to compile it with gcc, so I'm really interested on it

           

          Thanks a lot

           

          What forces you to use GCC on windows?

          Is there any specific reason why you would like to use GCC on Windows?

            • OpenCL with GCC
              koveras

              Well, I've seen that OpenCL works on Visual Studio, so I'm trying to check if OpenCL can be compiled with gcc on Windows, because on my subjects we use gcc.

                • OpenCL with GCC
                  genaganna

                   

                  Originally posted by: koveras Well, I've seen that OpenCL works on Visual Studio, so I'm trying to check if OpenCL can be compiled with gcc on Windows, because on my subjects we use gcc.

                   

                  I am not sure it is reasonable to support OpenCL libraries compatable with GCC on Windows.

                    • OpenCL with GCC
                      koveras

                      I think it is reasonable to support gcc on Windows, because it is the most used free compiler. If AMD support OpenCL on Linux, I think it shouldn't be difficult to support it on Windows. It's because I don't want to use Visual Studio, I prefer Eclipse + CDT plugin, and it use gcc.

                        • OpenCL with GCC
                          nou

                          i appreciate gcc/mingw support on windows. i develop mainly on linux but i want port my code to windows.

                            • OpenCL with GCC
                              TheAlchemist

                              I too would like a ATI Stream gcc-mingw build for Windows because of Eclipse CDT.

                              I actually built some gcc-mingw for ATI Stream 1.4, when the source was available.

                                • OpenCL with GCC
                                  genaganna

                                   

                                  Originally posted by: TheAlchemist I too would like a ATI Stream gcc-mingw build for Windows because of Eclipse CDT.

                                   

                                  I actually built some gcc-mingw for ATI Stream 1.4, when the source was available.

                                   

                                  Are you talking about 1.4 Brook+ and CAL? Are you able run all CAL and Brook+ samples?  if you are able run samples, it is not required gcc-mingw compatable CAL libraries.

                                   

                                  As a side note : Brook+ is now available at http://sourceforge.net/projects/brookplus/

                                   

                                    • OpenCL with GCC
                                      TheAlchemist

                                       

                                      Are you talking about 1.4 Brook+ and CAL? Are you able run all CAL and Brook+ samples?  if you are able run samples, it is not required gcc-mingw compatable CAL libraries.

                                       

                                       

                                       

                                      As a side note : Brook+ is now available at http://sourceforge.net/projects/brookplus/

                                       

                                      Truthfully, I can't remember anymore, but I do remember that my goal was to use Eclipse on Windows to run/debug ATI stream code.  It had something to do with not being able to link against some of the DLLs.

                            • OpenCL with GCC
                              TheProphet

                              In fact, that is quite easy to make a libOpenCL.a for MingW. I've done it, and now I can compile OpenCL examples with MingW.

                              The idea is to use the tool reimp found in mingw, which allows you to create an a import library for a DLL (ie create libXXX.a from a XXX.lib where XXX.lib is only the import library for XXX.dll ; I insist : it won't create a libXXX.a when XXX.lib is a general library, it only works for import libraries ; moreover, the name mangling in the DLL must not be C++ mangling : simple bare function names are OK).

                              1. Open a command prompt where the PATH contains the mingw\bin ; go to the ATIStreamSDK\lib\x86 where you find OpenCL.lib, and type reimp OpenCL.lib

                              You get OpenCL.def and libopencl.a -> this is what you want to link against.

                              2. When you compile your .c / .cpp using cl.h, add a compiler define _MSC_VER in order to define the stdcall convention, else the linker will not search for the good names into libopencl.a.

                              That's all ; it worked for me.

                              In case reimp tells you "bad or corrupt import lib" or something like that, you just have to use dlltool (included in mingw) to generate libopencl.a from OpenCL.def :

                              dlltool -l libopencl.a -d OpenCL.def -A -k

                              where OpenCL.def is for instance this file (.def contain export names from DLL) :

                              http://pastebin.com/f2ac38b2f

                               

                               

                                • OpenCL with GCC
                                  nou

                                  oh that is great. thanks

                                    • OpenCL with GCC
                                      TheProphet

                                      If necessary, in case where one fails to make its own libOpenCL.a, I can provide mine.

                                       

                                        • OpenCL with GCC
                                          TheAlchemist

                                           

                                          Originally posted by: TheProphet If necessary, in case where one fails to make its own libOpenCL.a, I can provide mine.

                                           

                                           

                                          I might ask for just that, thank you

                                            • OpenCL with GCC
                                              Fr4nz

                                              Hi all,

                                              did someone manage to use MinGW + Eclipse for OpenCL ? Any news with the "adapted" library?

                                              Unfortunately I'm still unable to use Eclipse, apparently the library created with the procedure indicated in the first post can't be seen by the compiler...

                                                • OpenCL with GCC
                                                  TheProphet

                                                  Haven't you forgotten to put the newly created libOpenCL.a in your compiler's lib directory ?

                                                  Don't forget also to link against this lib, once in the right directory ('g++ -D_MSC_VER -o example example.cpp -lOpenCL' for instance). In Eclipse, you just have to add a project option to link against libOpenCL.a.

                                                   

                                                    • OpenCL with GCC
                                                      Fr4nz

                                                       

                                                      Originally posted by: TheProphet Haven't you forgotten to put the newly created libOpenCL.a in your compiler's lib directory ?

                                                       

                                                      Don't forget also to link against this lib, once in the right directory ('g++ -D_MSC_VER -o example example.cpp -lOpenCL' for instance). In Eclipse, you just have to add a project option to link against libOpenCL.a.

                                                       

                                                       

                                                      Here's what I did:

                                                      1) I've copied  libopencl.a in the "lib" compiler directory;

                                                      2) I've added the -D_MSC_VER in the eclipse "defined symbols (-D)" compiler settings;

                                                      3) I've configured the OpenCL include folder pointing to the one contaning the CL folder (which is "ATI STREAM/Include");

                                                      4) I've added "opencl" in the compiler additional libraries section;

                                                      but still nothing. Here's the output:

                                                      **** Internal Builder is used for build               ****
                                                      gcc -D_MSC_VER -IC:\Program Files (x86)\ATI Stream\include -O0 -g3 -Wall -c -fmessage-length=0 -osrc\main.o ..\src\main.c
                                                      In file included from ..\src\main.c:4:
                                                      C:\Program Files (x86)\ATI Stream\include/CL/cl.h:61: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'cl_context_properties'
                                                      C:\Program Files (x86)\ATI Stream\include/CL/cl.h:436: warning: type defaults to 'int' in declaration of 'cl_context_properties'
                                                      C:\Program Files (x86)\ATI Stream\include/CL/cl.h:436: error: expected ';', ',' or ')' before '*' token
                                                      C:\Program Files (x86)\ATI Stream\include/CL/cl.h:444: warning: type defaults to 'int' in declaration of 'cl_context_properties'
                                                      C:\Program Files (x86)\ATI Stream\include/CL/cl.h:444: error: expected ';', ',' or ')' before '*' token
                                                      ..\src\main.c: In function 'main':
                                                      ..\src\main.c:87: warning: format '%d' expects type 'int', but argument 2 has type 'cl_uint'
                                                      ..\src\main.c:100: warning: implicit declaration of function 'clCreateContextFromType'
                                                      ..\src\main.c:100: warning: assignment makes pointer from integer without a cast
                                                      ..\src\main.c:122: warning: passing argument 5 of 'clGetContextInfo' from incompatible pointer type
                                                      C:\Program Files (x86)\ATI Stream\include/CL/cl.h:457: note: expected 'size_t *' but argument is of type 'cl_uint *'
                                                      Build error occurred, build is stopped
                                                      Time consumed: 78  ms.  

                                                      Where am I wrong? My sample runs fine under MSVS2008...

                                                        • OpenCL with GCC
                                                          TheAlchemist

                                                           

                                                          Originally posted by: Fr4nz


                                                           

                                                           

                                                          Where am I wrong? My sample runs fine under MSVS2008...

                                                           

                                                           

                                                          Could you post your code?  It seems like your code is fixable with a few casts...

                                                            • OpenCL with GCC
                                                              Fr4nz

                                                               

                                                              Originally posted by: TheAlchemist
                                                              Originally posted by: Fr4nz


                                                               

                                                               

                                                               

                                                               

                                                               

                                                               

                                                              Where am I wrong? My sample runs fine under MSVS2008...

                                                               

                                                               

                                                               

                                                               

                                                               

                                                               

                                                              Could you post your code?  It seems like your code is fixable with a few casts...

                                                               

                                                               

                                                              Well, let's suppose is fixable with some casts...this does not explain why the code runs correctly under MSVS2008 and under Linux (Ubuntu 9.10).

                                                              I think there's something wrong with my Eclipse configuration...do you have the time to describe, step by step, the procedure you have followed when you've configured Eclipse? It would be very helpful!

                                                              Thank you!

                                                               

                                                              PS: Do you use cl.h and cl_platform.h provided by ATI or the ones provided by Khronos?

                                                                • OpenCL with GCC
                                                                  TheProphet

                                                                  It works fine for me using the CL directory in "\program files\ATI Stream\include\CL" ; the cl.h found here starts with "Copyright (c) 2008-2009 The Khronos Group Inc.". However, the cl_platform.h found here starts with "Copyright (c) 2009 Advanced Micro Devices, Inc.  All rights reserved.".

                                                                  The line 61 of cl.h where you have your first error is for me :

                                                                  typedef intptr_t            cl_context_properties;

                                                                  please check in your mingw/include/stdint.h that you have those defines :

                                                                  typedef int intptr_t;
                                                                  typedef unsigned uintptr_t;

                                                                   

                                                                  Perhaps you're using a too old mingw version ?

                                                                  I think just adding this typedef should be enough.

                                                                   

                                                                    • OpenCL with GCC
                                                                      Fr4nz

                                                                      I have your same cl.h and cl_platform.h ... I really don't understand why I'm not able to make it work. Also stdint.h seems to be correct.

                                                                      Just out of curiosity, did you modify cl_platform.h (lines 96 and 98)?

                                                                      Anyway, do you have msn, icq, etc., so we could talk in a better way? If yes, please send me a PM.

                                                                      Thanks!

                                                                        • OpenCL with GCC
                                                                          TheProphet

                                                                          Before going further, I have noticed that I have only tested it with C++ compilation, not C.

                                                                          I see in your log that you are compiling C.

                                                                          Could you try to rename your main.c to main.cpp and compile with g++ instead of gcc ?

                                                                           

                                                                            • OpenCL with GCC
                                                                              Fr4nz

                                                                               

                                                                              Originally posted by: TheProphet Before going further, I have noticed that I have only tested it with C++ compilation, not C.

                                                                               

                                                                              I see in your log that you are compiling C.

                                                                               

                                                                              Could you try to rename your main.c to main.cpp and compile with g++ instead of gcc ?

                                                                               

                                                                               

                                                                              Done, this is what I get:

                                                                               

                                                                              **** Rebuild of configuration Debug for project OpenkDCI **** **** Internal Builder is used for build **** g++ -IC:\Program Files (x86)\ATI Stream\include -O0 -g3 -Wall -c -fmessage-length=0 -omain.o ..\main.cpp In file included from ..\main.cpp:5: C:\Program Files (x86)\ATI Stream\include/CL/cl.h:61: error: 'intptr_t' does not name a type C:\Program Files (x86)\ATI Stream\include/CL/cl.h:436: error: ISO C++ forbids declaration of 'cl_context_properties' with no type C:\Program Files (x86)\ATI Stream\include/CL/cl.h:436: error: expected ',' or '...' before '*' token C:\Program Files (x86)\ATI Stream\include/CL/cl.h:444: error: ISO C++ forbids declaration of 'cl_context_properties' with no type C:\Program Files (x86)\ATI Stream\include/CL/cl.h:444: error: expected ',' or '...' before '*' token ..\main.cpp: In function 'int main(int, char**)': ..\main.cpp:89: warning: format '%d' expects type 'int', but argument 2 has type 'cl_uint' C:\Program Files (x86)\ATI Stream\include/CL/cl.h:444: error: too many arguments to function '_cl_context* clCreateContextFromType(int)' ..\main.cpp:102: error: at this point in file ..\main.cpp:124: error: invalid conversion from 'cl_uint*' to 'size_t*' ..\main.cpp:124: error: initializing argument 5 of 'cl_int clGetContextInfo(_cl_context*, cl_context_info, size_t, void*, size_t*)' ..\main.cpp:127: error: invalid conversion from 'void*' to '_cl_device_id**' Build error occurred, build is stopped Time consumed: 78 ms.

                                                                                • OpenCL with GCC
                                                                                  TheProphet

                                                                                  Can you try to #include <stdint.h> in your main.c *before* cl.h ?

                                                                                   

                                                                                    • OpenCL with GCC
                                                                                      Fr4nz

                                                                                       

                                                                                      Originally posted by: TheProphet Can you try to #include in your main.c *before* cl.h ?

                                                                                       

                                                                                      Well, at the end yesterday I decided to move the development under Ubuntu 9.04, I was tired of that situation. Now all works perfectly

                                                                                      It is clear that the problem wasn't the library but something related to the compiling phase (maybe something in the cl_platform.h header ?).

                                                                                      I'll wait for future betas in order to see if something changes for minGW...

                                                                                       

                                                            • OpenCL with GCC
                                                              TheAlchemist

                                                               

                                                              Originally posted by: TheProphet In fact, that is quite easy to make a libOpenCL.a for MingW. I've done it, and now I can compile OpenCL examples with MingW.

                                                               

                                                              The idea is to use the tool reimp found in mingw, which allows you to create an a import library for a DLL (ie create libXXX.a from a XXX.lib where XXX.lib is only the import library for XXX.dll ; I insist : it won't create a libXXX.a when XXX.lib is a general library, it only works for import libraries ; moreover, the name mangling in the DLL must not be C++ mangling : simple bare function names are OK).

                                                               

                                                              1. Open a command prompt where the PATH contains the mingw\bin ; go to the ATIStreamSDK\lib\x86 where you find OpenCL.lib, and type reimp OpenCL.lib

                                                               

                                                              You get OpenCL.def and libopencl.a -> this is what you want to link against.

                                                               

                                                              2. When you compile your .c / .cpp using cl.h, add a compiler define _MSC_VER in order to define the stdcall convention, else the linker will not search for the good names into libopencl.a.

                                                               

                                                              That's all ; it worked for me.

                                                               

                                                              In case reimp tells you "bad or corrupt import lib" or something like that, you just have to use dlltool (included in mingw) to generate libopencl.a from OpenCL.def :

                                                               

                                                              dlltool -l libopencl.a -d OpenCL.def -A -k

                                                               

                                                              where OpenCL.def is for instance this file (.def contain export names from DLL) :

                                                               

                                                              http://pastebin.com/f2ac38b2f

                                                               

                                                               

                                                               

                                                               

                                                               

                                                              Wow, thanks for the tip!  I didn't know about reimp/dlltool.

                                                               

                                                              I'll have to give that a try when I get a chance.  I'll probably put together a screencast on OpenCL + Eclipse then.

                                                              • OpenCL with GCC
                                                                berathebrain

                                                                I am struggling to create an libopencl.a. I have followed the instrucions from TheProphet but i end up with theese errors:

                                                                 

                                                                'Invoking: MinGW C++ Linker'

                                                                g++ -L"e:\Download\1 Firefox\bin" --enable-stdcall-fixup -o"Reduction.exe"  ./src/Reduction.o ./src/SDKFile2.o   -lOpenCL

                                                                e:\Download\1 Firefox\bin/libOpenCL.a(dgfis00050.o).idata$7+0x0): undefined reference to `_head_libopencl_a'

                                                                e:\Download\1 Firefox\bin/libOpenCL.a(dgfis00039.o).idata$7+0x0): undefined reference to `_head_libopencl_a'

                                                                collect2: ld returned 1 exit status

                                                                make: *** [Reduction.exe] Error 1



                                                                Am I doing something wrong?

                                                                I have defind _MSC_VER

                                                                'Invoking: MinGW C++ Linker' g++ -L"e:\Download\1 Firefox\bin" --enable-stdcall-fixup -o"Reduction.exe" ./src/Reduction.o ./src/SDKFile2.o -lOpenCL e:\Download\1 Firefox\bin/libOpenCL.a(dgfis00050.o):(.idata$7+0x0): undefined reference to `_head_libopencl_a' e:\Download\1 Firefox\bin/libOpenCL.a(dgfis00039.o):(.idata$7+0x0): undefined reference to `_head_libopencl_a' collect2: ld returned 1 exit status make: *** [Reduction.exe] Error 1

                                                                  • OpenCL with GCC
                                                                    TheProphet

                                                                    Can you give more details :

                                                                    - when have you got this error ? when trying to build libopencl.a ? when trying to link against libopencl.a ?

                                                                    - what is your version of gcc/g++ ?

                                                                    I have read that those "_head_" symbols got exported by the libopencl.a whereas they shouldn't (because they don't exist) when the reimp tool did not his work correctly. I suggest you to take the OpenCL.def file here : http://pastebin.com/f2ac38b2f

                                                                    and then build libopencl.a by this command :

                                                                    dlltool -l libopencl.a -d OpenCL.def -A -k

                                                                     

                                                                      • OpenCL with GCC
                                                                        berathebrain

                                                                        Actually it works now, but thanks anyhow. It seems that I did not even need to make OpenCL.a, instead I used the original OpenCL.lib! The only thing that I had to do is make a preprocessor definition of "_MSC_VER=1500" and now the gcc sucessfully recognizes export functions of that lib file.

                                                                        BTW, I'm using gcc 4.4.1 for windows and Eclipse.

                                                                        PS: I had to make some changes to cl_platform.h and cl.hpp.

                                                                          • OpenCL with GCC
                                                                            genaganna

                                                                             

                                                                            Originally posted by: berathebrain Actually it works now, but thanks anyhow. It seems that I did not even need to make OpenCL.a, instead I used the original OpenCL.lib! The only thing that I had to do is make a preprocessor definition of "_MSC_VER=1500" and now the gcc sucessfully recognizes export functions of that lib file.

                                                                             

                                                                            BTW, I'm using gcc 4.4.1 for windows and Eclipse.

                                                                             

                                                                            PS: I had to make some changes to cl_platform.h and cl.hpp.

                                                                             

                                                                            Berathebrain,

                                                                                      Could you please list all changes you made to cl_platform.h and cl.hpp?

                                                                              • OpenCL with GCC
                                                                                berathebrain

                                                                                Sorry, looks like It all works without any changes to the cl.hpp or cl_platform.h. While I was trying to make the samples to work with eclipse I got carried away... Soon I realized that my efforts were futile. Then I gave up on the samples and tried to use only OpenCL without SDKUtil.

                                                                                I succeeded when I read about _MSC_VER definition from TheProphet.

                                                                                Thank you guys.

                                                                                Now I successfully use cl.hpp.

                                                                                Cheers