8 Replies Latest reply on Oct 23, 2009 3:02 PM by oscarbarenys1

    Getting IL code from OpenCL

    hazeman

      It's possible to generate IL code using OpenCL compiler from SDK. Here is how .

      Go to SDK/bin directory and copy your opencl source file as source.cl. Then issue from command line the following instructions

      ./clc --emit=llvmbc source.cl -o kernel.bc

      ./llc -regalloc=amdil -filetype=asm -march=amdil kernel.bc -o kernel.il

      ( for windows users omit ./ )

      Done . kernel.il is our result.

      You can try to enable optimizations ( -O3 -enable-fp-mad -enable-unsafe-fp-math as options to the llc ) but it looks like the compiler doesn't use it.

      On the pessimistc note, the quality of generated code doesn't look too good. I think that at the moment we have only rudimentary OpenCL compiler. Judging by the time it took ATI to get it done ( 5 months longer than others ) we can't expect good compiler any time soon.

      PS. llc --versions gives Registered Targets: amdil  - ATI RADEON HD4XXX series graphics cards. And yet at the same time we get information that OpenCL compiler is created for 58xx ( this argument was given as justification to low opencl performance on 48xx ).

       

       

       

       

       

       

        • Getting IL code from OpenCL
          genaganna

          PS. llc --versions gives Registered Targets: amdil  - ATI RADEON HD4XXX series graphics cards. And yet at the same time we get information that OpenCL compiler is created for 58xx ( this argument was given as justification to low opencl performance on 48xx ).

          Hazeman,

                         could you please post testcase which shows poor performance on 4XXX?

          • Getting IL code from OpenCL
            MicahVillmow
            Hazeman,
            What you are see being generated is unoptimized code only.
              • Getting IL code from OpenCL
                hazeman

                Correct me if I'm wrong. The libOpenCL is calling clc and llc to generate IL and then uses CAL backend to compile to ISA - and I assume that you are talking about CAL backend optimizations.

                 

                So if it's true I'm going to leave my conclusions without any change, as CAL optimizer has it's own problems ( and btw test results confirm it ). And CAL can't make some optimizations ( like using mads when llc generates mul_ieee ).

                 

              • Getting IL code from OpenCL
                MicahVillmow
                Hazemen,
                The bitcode that you are passing into llc is not the same bitcode that the runtime passes to llc.
                  • Getting IL code from OpenCL
                    hazeman

                     

                    Originally posted by: MicahVillmow Hazemen, The bitcode that you are passing into llc is not the same bitcode that the runtime passes to llc.


                    When I have some spare time I'll verify this as intercepting llc call from libopencl isn't that hard ( and I'll try to update this "guide" ). But I can say that bit code generated by the clc didn't look bad ( clc generates also text version ). So for now i have reasonable doubts if changing clc step ( to match the one in libopencl ) will give better code.

                    Of course you could simply tell us what to do ( I assume some additional flags to clc ).

                     

                      • Getting IL code from OpenCL
                        oscarbarenys1

                        I have actually done exactly that a wrapper to ATI CAL..

                        It's working on Windows and Linux as a note I tested your kernel and as Micah said it's much better code than what you get with your implementation..

                        Also note that it has also device assembly code (so it gets info as would a SKA for OpenCL..)

                        One limitation of my approach vs. yours is that you can theoretically run that in Mac (using Wine) for getting AMD IL.. My implementation can't as ATI doesn't ship CAL libraries in MacOS an also the AMD support in MacOs seems to do not depend on CAL libraries (I can't search it)..

                         

                          • Getting IL code from OpenCL
                            oscarbarenys1

                            Sorry the link is http://oscarbg.blogspot.com/2009/10/cal-wrapper-for-getting-amd-il-from.html

                             

                            Originally posted by: oscarbarenys1 I have actually done exactly that a wrapper to ATI CAL..

                             

                            It's working on Windows and Linux as a note I tested your kernel and as Micah said it's much better code than what you get with your implementation..

                             

                            Also note that it has also device assembly code (so it gets info as would a SKA for OpenCL..)

                             

                            One limitation of my approach vs. yours is that you can theoretically run that in Mac (using Wine) for getting AMD IL.. My implementation can't as ATI doesn't ship CAL libraries in MacOS an also the AMD support in MacOs seems to do not depend on CAL libraries (I can't search it)..