3 Replies Latest reply on Sep 23, 2014 10:16 AM by tomschi

    using declaration problem with built-in functions

    tomschi

      i have the following code that yields an compile-time error (using OpenCL compiler, AMD APP 1445.5 on Intel Core i7, using static C++ extensions):

       

      namespace myNS

      {

        using ::fmin;

      }

       

      void test()

      {

        float f = myNS::fmin(1.0f, 2.0f);

      }

       

      results in

       

      Error: "fmin" has already been declared in the current scope

       

      Error: "fmin" has already been declared in the current scope

       

      Error: "fmin" has already been declared in the current scope

       

      Error: "fmin" has already been declared in the current scope

       

      Error: "fmin" has already been declared in the current scope

       

      Error: "fmin" has already been declared in the current scope

       

      Error: "fmin" has already been declared in the current scope

       

      Error: "fmin" has already been declared in the current scope

       

      Error: "fmin" has already been declared in the current scope

       

      Error: "fmin" has already been declared in the current scope

       

      Error: "fmin" has already been declared in the current scope

       

      "OpenCL-CPP-JIT-Source", line 9: error: a value of type "double16" cannot be

                used to initialize an entity of type "float"

          float f = myNS::fmin(1.0f, 2.0f);


      i can get rid of the error if i insert the following declaration at the begin of the code snippet:


      float fmin(float, float);


      This is not specific to fmin, but i assume for all built-in, overloaded (?) functions (i've only tested a few: fabs, min, max...)

      Why do i have to declare the built-in function in this case first?

      Have i missed something or is this a compiler problem ?


      thanks and regards,

        tomschi

        • Re: using declaration problem with built-in functions
          dipak

          Hi,

          I checked it and my observation was same as yours. I've asked someone from compiler team and will get back to you as soon as I get any reply.

           

          Regards,

          • Re: using declaration problem with built-in functions
            dipak

            Hi,

            As I came to know that the compilation errors are due to conflict with the built-in functions defined in our implementation. You can use those built-in functions directly from your own code as follows:


            void test()

            {

              float f = ::fmin(1.0f, 2.0f);

            }


            Regards

              • Re: using declaration problem with built-in functions
                tomschi

                thanks for the reply,

                 

                i'm aware of the fact that my code compiles using the built-in from the global namespace,

                but why can't a built-in function not be referenced in a using declaration without declaring it first?

                i don't know any internals of the OpenCL compiler, but i always thought that built-ins ressemble

                already defined functions (just as a theoretical model) and thus a function declaration in some sense (float fmin(float, float))

                should be already present  (and i don't have to write it :-)

                 

                my use case is a wrapper library (OpenCL/CUDA/Host C++), where i would like to have a "fmin" in a dedicated namespace.

                i also would like to avoid implementing a dummy fmin in the namespace that simply calls the ::fmin (avoid any redudant piece of code, also the declaration if possible).

                 

                thanks and regards,

                  tomschi