cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

koveras
Journeyman III

OpenCL with GCC

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

0 Likes
32 Replies
genaganna
Journeyman III

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?

0 Likes

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.

0 Likes

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.

0 Likes

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.

0 Likes

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

0 Likes

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.

0 Likes

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/

 

0 Likes

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.

0 Likes

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

 

oh that is great. thanks

0 Likes

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

 

0 Likes

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

0 Likes

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...

0 Likes

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.

 

0 Likes

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...

0 Likes

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...

0 Likes

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?

0 Likes

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.

 

0 Likes

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!

0 Likes

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 ?

 

0 Likes

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.

0 Likes

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

 

0 Likes

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...

 

0 Likes

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.

0 Likes

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

0 Likes

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

 

0 Likes

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.

0 Likes

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?

0 Likes

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

0 Likes

Berathebrain,

         Could you please decribe all changes you made to work with GCC and Elipse in windows? Your message will be very helpful for other people who faces same problem.

0 Likes

OK.

1)So first step is to download eclipse from http://www.eclipse.org/downloads/.

Choose Eclipse IDE for C/C++ Developers (79 MB).

2) Download GCC 4.4.1 from http://www.tdragon.net/recentgcc/

I used this version http://sourceforge.net/projects/tdm-gcc/files/TDM-MinGW%20Installer/1.908.0/tdm-mingw-1.908.0-4.4.1-2.exe/download

3)Copy your OpenCL.lib to your lib folder in mingw\lib directory, you don't need to copy it but I did it anyway. OpenCL.lib is usually located in "C:\Program Files\ATI Stream\lib"

4)Start Eclipse and create a new C/C++ project, add some source files.

5)Right click on your project, go to properties, select C/C++ Build, select Setings, choose "GCC C++ Compiler->Preprocessor", define new symbol "_MSC_VER=1500" without quotes. Select "GCC C++ Compiler->Directories", add new include Path where your Stream SDK is installed. For example : "C:\Program Files\ATI Stream\include"

Choose MinGW C++ Linker->Libraries, add new library named "OpenCL" without quotes, if you did not copied your OpenCL.lib to your mingw\lib folder then you should also add library searh path that points to your OpenCL.lib file.

6) After all the settings you are ready to build your OpenCL code using MingW and Eclipse. I'm using Windows7 64bit, so it works on this platform, don't know about the other ones.

PS: Samples from ATI Stream don't work because they use SDKUtil library, if you somehow manage to write those OpenCL samples without SDKUtils then they should build.

Hope this helps,

cheers

0 Likes

berathebrain,

Thank you very much.

0 Likes