14 Replies Latest reply on Apr 3, 2011 1:52 AM by sfmraja

    SOLVED: Problem Compiling OpenCL to 64-bit (C++)

    sir.um
      MinGW 64

      I'm using the C++ bindings for OpenCL and the MinGW 64-bit compiler for Windows 7, 64-bit.

      My Build Commands, Source code, and Program Output are attached.

      The code compiles fine, and will run as a 64-bit program, until it hits OpenCL code. When it hits OpenCL It hangs for a while then crashes.

      Any help is appreciated.

      Thanks
      -Chris

       

      ----- Build Command ----- g++ -IC:\Users\Chris\workspaceC++_64\OpenCL\includes -O0 -g3 -Wall -c -fmessage-length=0 -osrc\HelloWorld.o ..\src\HelloWorld.cpp In file included from C:\Users\Chris\workspaceC++_64\OpenCL\includes/CL/opencl.h:44:0, from C:\Users\Chris\workspaceC++_64\OpenCL\includes/CL/cl.hpp:161, from ..\src\HelloWorld.cpp:9: C:\Users\Chris\workspaceC++_64\OpenCL\includes/CL/cl_gl_ext.h:44:4: warning: "/*" within comment g++ -LC:\Program Files (x86)\ATI Stream\lib\x86_64 -oOpenCL.exe src\HelloWorld.o -lOpenCL Build complete for project OpenCL Time consumed: 1470 ms. ----- Program ----- //OpenCL Includes #define __NO_STD_VECTOR //Use cl::vector instead of STL version #include <CL/cl.hpp> //C++ API Includes #include <iostream> #include <cstdlib> using namespace std; using namespace cl; int main() { cout<<"Hello, World!"<<endl; cl_int err; //Request Supported Platforms from OpenCL vector<Platform> platformList; cout<<"Platform Vector Created"<<endl; err = Platform::get(&platformList); cout<<"After Get Platform List"<<endl; } ----- Program Output ----- Hello, World! Platform Vector Created (Hangs here and then crashes)

        • Problem Compiling OpenCL to 64-bit (C++)
          genaganna

           

          Originally posted by: sir.um I'm using the C++ bindings for OpenCL and the MinGW 64-bit compiler for Windows 7, 64-bit.

           

          My Build Commands, Source code, and Program Output are attached.

           

          The code compiles fine, and will run as a 64-bit program, until it hits OpenCL code. When it hits OpenCL It hangs for a while then crashes.

           

          Any help is appreciated.

           

          Thanks -Chris

           

           

           

          I am able to run 32 bit sample after building MinGW.  I have not tested with 64bit as i donot have that.

          From where you have downloaded in MinGW-64.

          • Problem Compiling OpenCL to 64-bit (C++)
            dravisher

            I hope you (AMD) will continue to expand on compiler support on Windows. In my limited tests I've had very poor results on MinGW, performance has been much lower than using MSVC. However MinGW-64 shows excellent performance. So I really hope you will either bring support for MinGW-64, or (even better) bring Open64 over to Windows and support that with OpenCL :-)

            • Problem Compiling OpenCL to 64-bit (C++)
              genaganna

               

              Originally posted by: sir.um I'm using the C++ bindings for OpenCL and the MinGW 64-bit compiler for Windows 7, 64-bit.

              My Build Commands, Source code, and Program Output are attached.

              The code compiles fine, and will run as a 64-bit program, until it hits OpenCL code. When it hits OpenCL It hangs for a while then crashes.

              Any help is appreciated.

               



              We reported this issue to developers. Thank you for reporting this issue to us.

                • Problem Compiling OpenCL to 64-bit (C++)
                  sir.um

                  No Problem. Thanks for looking into it. :-)

                  Just for a quick reference, here is something which I posted on the MinGW forum, but just realized that I didn't post here. The exact line it died (quoted from one of my posts on the MinGW forum)

                  See MinGW forum for more info. (exact GDB output, etc.) Link again:

                  https://sourceforge.net/projects/mingw-w64/forums/forum/723798/topic/3838675

                  -Chris

                  ...the function call in the code above: Platform::get(&platformList); --- dies inside cl.hpp on line 1359: cl_int err = ::clGetPlatformIDs(0, NULL, &n); --- which is a C++ binding for the C function inside cl.h on line 447: /* Platform API */ extern CL_API_ENTRY cl_int CL_API_CALL clGetPlatformIDs(cl_uint /* num_entries */, cl_platform_id * /* platforms */, cl_uint * /* num_platforms */) CL_API_SUFFIX__VERSION_1_0;

                    • Problem Compiling OpenCL to 64-bit (C++)
                      saleel

                      Looks like its a bug in the Mingw64 linker.  It works on Mingw32

                      The work around to make it work is to create a libopencl.a  and place it in the $SDKROOT\lib folder

                      To make a lib.a fill do

                      1. On the OpenCL.dll file in $SDKROOT\bin

                      > gendef OpenCL.dll  

                      2. Copy the OpenCL.def file to Lib directory

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

                      (You may need cygwin for this)

                       

                      Once you have this you should be able to compile and run on Mingw64

                       

                        • Problem Compiling OpenCL to 64-bit (C++)
                          sir.um

                          By "$SDKROOT\bin" I assume you mean:

                          "C:\Program Files (x86)\ATI Stream\bin"

                          This folder contains no files, only the folders: "x86" & "x86_64". Inside these folders there is no "OpenCL.dll" but there are files named "atiocl.dll" and "atiocl64.dll", respectively, is this the file you mean?

                            • Problem Compiling OpenCL to 64-bit (C++)
                              sir.um

                              As it is late and no one is awake, I tried to figure this out on my own. Didn't go so well...

                              I ran the command:

                              C:\Program Files (x86)\ATI Stream\bin\x86_64>gendef atiocl64.dll


                              I then copied the resulting file "atiocl64.def" to the folder:

                              C:\Program Files (x86)\ATI Stream\lib


                              then ran the following command:

                              C:\Program Files (x86)\ATI Stream\lib>dlltool -l libopencl.a -d atiocl64.def -k -A


                              This produced the file "libopencl.a" in the folder:

                              When I Compiled and ran with this configuration, I had the exact same problem. I noticed that since I needed to go an additional subdir below the bin dir that I would try it with the lib as well. I moved the "libopencl.a" file to the x86_64 subdir, and recompiled my program. I received the following compile error:

                               

                              g++ -IC:\Users\Chris\workspaceC++_64\Matrix_Mult_OpenCL\includes -O0 -g3 -Wall -c -fmessage-length=0 -osrc\test.o ..\src\test.cpp
                              In file included from C:\Users\Chris\workspaceC++_64\Matrix_Mult_OpenCL\includes/CL/opencl.h:44,
                                               from C:\Users\Chris\workspaceC++_64\Matrix_Mult_OpenCL\includes/CL/cl.hpp:161,
                                               from ..\src\test.cpp:12:
                              C:\Users\Chris\workspaceC++_64\Matrix_Mult_OpenCL\includes/CL/cl_gl_ext.h:44:4: warning: "/*" within comment
                              g++ -LC:\Program Files (x86)\ATI Stream\lib\x86_64 -oMatrix_Mult_OpenCL.exe src\test.o -lOpenCL
                              src\test.o:C:/Users/Chris/workspaceC++_64/Matrix_Mult_OpenCL/includes/CL/cl.hpp:1359: undefined reference to `clGetPlatformIDs'
                              src\test.o:C:/Users/Chris/workspaceC++_64/Matrix_Mult_OpenCL/includes/CL/cl.hpp:1366: undefined reference to `clGetPlatformIDs'
                              collect2: ld returned 1 exit status
                              Build error occurred, build is stopped
                              Time consumed: 1829  ms.


                              I then moved it back the the parent directory:

                              C:\Program Files (x86)\ATI Stream\lib


                              and renamed it to "atiocl64.a" to match the naming convention of the previously encountered files. I then recompiled and ran my program. This removed the compile error, and put me right back were I started. A program that hangs when it hits OpenCL code.

                              //
                              //MinGW64
                              //
                              At this point I realized that MinGW32 was still set in my path, So I reset my Path to be MinGW64, deleted the old files and redid did gendef and dlltool commands. With "libopencl.a" (compiled via MinGW64) in the directory:

                              C:\Program Files (x86)\ATI Stream\lib


                              Right back were we started. Program compiles fine, but hangs when it hits OpenCL code. This part is a bit interesting though. When I moved the MinGW64 version of "libopencl.a" to the "lib\x86_64" directory and recompiled, there were no compile errors. However, when I ran the program, it crashes without any output. I assume that means that it died before it even got to the OpenCL code. This discrepancy is the only reason I left the previous (mistake) play-by-play in my response. Although, it is probably unrealated and can be ignored.

                              I again moved the file back to:

                              C:\Program Files (x86)\ATI Stream\lib


                              and renamed it to "atiocl64.a" to match the naming convention of the previously encountered files. Compiled fine, ran and hung on OpenCL call. I then moved "atiocl64.a" file to "lib\x86_64". Compies fine, but crashes like before (No output at all).

                              Finally, I removed the "64" from the filename, and moved it back to the root lib directory. Compiled fine, hung on OpenCL. However, when I moved THIS file to the "lib\x86_64" directory, it compiled fine, ran (WITH OUTPUT) but hung on the OpenCL code. I assume this is because, due to the lack of "64" in the filename, opencl ignored it. Just a guess.

                              Well, this is probably entirely too long for something that is due to my ignorance, but thanks for your time and help.

                              -Chris

                                • Problem Compiling OpenCL to 64-bit (C++)
                                  nou

                                  no you must create that .a file from OpenCL.dll and not from atiocl64.dll. try find it in C:\Windows\System32

                                    • Problem Compiling OpenCL to 64-bit (C++)
                                      sir.um

                                      YAAAAAAAAAAAAAY!!!!!!!!!!!!!!!!!!!! IT WORKED! Thank you so much! All of you! I've been working on this for Months! (Sigh) Finally.

                                       

                                      Originally posted by: nou

                                      no you must create that .a file from OpenCL.dll and not from atiocl64.dll. try find it in C:\Windows\System32



                                      You were right, OpenCL.dll is in:

                                       

                                      C:\Windows\System32\OpenCL.dll


                                      When you move the generated "OpenCL.def" file to the "Lib directory":

                                       

                                      Originally posted by: saleel

                                      2. Copy the OpenCL.def file to Lib directory

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

                                      (You may need cygwin for this)



                                      you actually need to put it in the "x86_64" sub folder:

                                       

                                      C:\Program Files (x86)\ATI Stream\lib\x86_64


                                      then run the dlltool to generate "libopencl.a" from there. I made a little batch file to do it all. (This is assuming your dirs are like mine. I chose all the defaults in the ATI Stream SDK install, so, assuming you're running windows (64-bit), I'm pretty sure it should be the same. Otherwise, just take out the "(x86)" part from the Program Files Directory name)

                                      Thanks again,
                                      -Chris

                                      cd "C:\Windows\system32" gendef OpenCL.dll move OpenCL.def "C:\Program Files (x86)\ATI Stream\lib\x86_64" cd "C:\Program Files (x86)\ATI Stream\lib\x86_64" dlltool -l libopencl.a -d OpenCL.def -k -A echo "All Done!"