3 Replies Latest reply on Nov 16, 2011 9:55 PM by gapon

    Detecting OpenCL in linux

    bubu

      Hi,

       

      I have a small problem under linux.... how could I detect the presence of OpenCL without calling a dynamic library? If I call any clXXXXX function but the libOpenCL.so is not present on the system then my app will fail to execute.

      Parsing the ld.conf or the LD path sounds very complicated.

       

      Does Khronos incllude some kind on inlined function ( without any .so dependency ) for this, pls?

       

      thx.

        • Detecting OpenCL in linux
          nou

          IMHO your only option is use dlopen("libOpenCL.so", RTDL_LAZY) and then dlsym() every function that you use.

            • Detecting OpenCL in linux
              sonicx

              While i agree with nou, it'll probably be easier to just wrap your app in some simple .sh for linux. If you distribute binaries (which i assumed you do, cause the source wouldnt even compile without that lib) you may have the same problem for lots of libraries.

              So you could for example have a wrapper that does a "ldd yourapp" and checks the list that comes out, and produces a nice message listing the missing libs.

            • Detecting OpenCL in linux
              gapon

               

              Originally posted by: bubu Hi, 

              I have a small problem under linux.... how could I detect the presence of OpenCL without calling a dynamic library? If I call any clXXXXX function but the libOpenCL.so is not present on the system then my app will fail to execute.

              Parsing the ld.conf or the LD path sounds very complicated.

              If you're deploying a binary application which requires a shared library then there is always an option of using 'ldd' to see if all libraries are present. See what happened after I removed libOpenCL.so.1 from my test installation:

               

              % ldd /opt/AMDAPP/samples/opencl/bin/x86_64/HelloCL

                      linux-vdso.so.1 =>  (0x00007fff819fd000)

                      libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003398c00000)

                      libdl.so.2 => /lib64/libdl.so.2 (0x0000003398800000)

                      libOpenCL.so.1 => /opt/AMDAPP/lib/x86_64/libOpenCL.so.1 (0x00002b251051b000)

                      libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x000000339e400000)

                      libm.so.6 => /lib64/libm.so.6 (0x0000003398400000)

                      libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x000000339d800000)

                      libc.so.6 => /lib64/libc.so.6 (0x0000003398000000)

                      /lib64/ld-linux-x86-64.so.2 (0x0000003397c00000)

              % ls -al /opt/AMDAPP/lib/x86_64/libOpenCL*

              lrwxrwxrwx 1 root root    14 Aug 15 19:04 /opt/AMDAPP/lib/x86_64/libOpenCL.so -> libOpenCL.so.1

              -rwxr--r-- 1 root root 20864 Jul 18 11:09 /opt/AMDAPP/lib/x86_64/libOpenCL.so.1

              % mv /opt/AMDAPP/lib/x86_64/libOpenCL.so.1 /opt/AMDAPP/lib/x86_64/libOpenCL.so.1.disabled

               

              % ldd /opt/AMDAPP/samples/opencl/bin/x86_64/HelloCL

                      linux-vdso.so.1 =>  (0x00007fff863fd000)

                      libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003398c00000)

                      libdl.so.2 => /lib64/libdl.so.2 (0x0000003398800000)

                      libOpenCL.so.1 => not found

                      libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x000000339e400000)

                      libm.so.6 => /lib64/libm.so.6 (0x0000003398400000)

                      libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x000000339d800000)

                      libc.so.6 => /lib64/libc.so.6 (0x0000003398000000)

                      /lib64/ld-linux-x86-64.so.2 (0x0000003397c00000)