9 Replies Latest reply on May 13, 2013 11:19 PM by jaidotsh

    Bolt video on YouTube

    bsp2020

      Hi,

      I'm trying out the Bolt library and watched the Bolt video on YouTube (http://www.youtube.com/watch?v=p1eWgRa-JQE). However, when I typed in the example code, it does not compile. I can't figure out what I did wrong. Please, help.

       

      // HelloWorld.cpp : Defines the entry point for the console application.

      //

       

      #include "stdafx.h"

      #include <bolt/cl/transform.h>

      #include <iostream>

      #include <algorithm>

       

      BOLT_FUNCTOR(StringFunctor,

      struct StringFunctor

      {

          char operator() ( const char& in )

          {

              return in + 1;

          };

      };

      );

       

      BOLT_CREATE_TYPENAME( char );

       

      int _tmain(int argc, _TCHAR* argv[])

      {

          // Initialize and print an input string

          std::string inputString( "GdkknVnqkc" );

          std::cout << "input string: " << inputString << std::endl;

       

          // Create input and ourput buffers

          std::vector< char > inputVec( inputString.begin(), inputString.end() );

          std::vector< char > outputVec( inputString.size() );

       

          // This calls into OpenCL to do the work

          bolt::cl::transform( inputVec.begin(), inputVec.end(), outputVec.begin(), StringFunctor( ) );

       

          // trasfer data to host memory from device memory.

          std::string outputString( outputVec.data(), outputVec.size() );

          std::cout << "output string: " << outputString << std::endl;

       

                return 0;

      }

       

      The error I'm getting is

      D:\Download\AMD\Bolt 1.0-Beta_VS2012\include\bolt/cl/clcode.h(87): error C2338: Bolt< error >: Unknown typename; define missing TypeName with Bolt provided macro's

       

      I"m sure I'm missing something simple. But, I can't figure it out.

        • Re: Bolt video on YouTube
          jaidotsh

          Hi bsp2020,

           

          This is issue is caused by the introduction of the device_vector iterator in the latest release. To solve this compilation error, you have to use bolt's helper macros to create a device_vector iterator of <char> typename and also create a ClCode string for it. So to conclude, you have to add the following lines after

          BOLT_CREATE_TYPENAME( char );

           

          BOLT_CREATE_TYPENAME( bolt::cl::device_vector< char >::iterator );
          BOLT_CREATE_CLCODE( bolt::cl::device_vector< char >::iterator, bolt::cl::deviceVectorIteratorTemplate );
          

           

          Please refer to http://hsa-libraries.github.io/Bolt/html/group__ClCode.html for detailed explanation of Bolt Macros 

           

          - Jay

            • Re: Bolt video on YouTube
              bsp2020

              Thanks for the answer. They should have shown the correct code in that video. I wonder how he was able to compile and run that code without

               

              BOLT_CREATE_TYPENAME( bolt::cl::device_vector< char >::iterator );

                • Re: Bolt video on YouTube
                  jaidotsh

                  Hi bsp2020,

                   

                  As Kent explained, the library we used in the video is old and the library has changed since then. So you just need to concatenate device_vector<char>::iterator to the kernel using the Bolt Macros if you're working on our current release.

                   

                  Well, we have made some more changes . Henceforth, you need not use Bolt Macros on OpenCL built-in data types (e.g. int, char, short etc. ) and functors1. This update is currently in our develop branch on GitHub. Develop branch has the latest fixes and updates from Bolt contributors. So the code in the video will still work, provided you remove the line below if you're working on develop.

                   

                  BOLT_CREATE_TYPENAME( char );
                  

                   

                  I'm not aware of the VS2010 issue. I'll look into it.

                   

                  1   I'm referring to the Bolt provided functors like bolt::cl::plus<>()

                   

                  - Jay

                    • Re: Bolt video on YouTube
                      bsp2020

                      Jay/Ken,

                      Thanks for the kind answer. I'm very interested in learning Bolt and contributing to the library. I was going to write radix sort using Bolt as an exercise but it seem that the algorithm that are currently implemented are not enough to do that. I can use transform and scan algorithm to figure out what elements to move and where to move them. But it does not look like there is an algorithm to scatter the data. Am I missing something?

                       

                      Also, it seem CUDA thrust is much more mature and has many more algorithms already implemented. Do you know if Apache license 2.0 that both library uses allow porting code from one another?

                       

                      Thanks

                       

                      Brian

                        • Re: Bolt video on YouTube
                          jaidotsh

                          That's good to hear Brian. You are always welcome to contribute to Bolt. You can do a pull request to our develop branch on GitHub.

                          I think radix sort is already implemented in Bolt sort API for integers and unsigned integers, please have a look.

                          Yes, you're right about scatter API missing from Bolt. It will be added in our future releases.

                          Since both the libraries use the same license, it's okay to port code.

                           

                          - Jay

                            • Re: Bolt video on YouTube
                              bsp2020

                              Jay,

                              Thanks for answering my question. I knew that there was Radix sort already implemented in Bolt, in sort algorithm. I just wanted to use Bolt library to write one as an exercise, to learn how to use Bolt. I have not used C++ STL much and just started learning CUDA style parallel programming. So, I thought that it may be a good exercise to write Radix sort, since I have written it in CUDA, not too long ago. I would be an interesting exercise .

                               

                              How can I make sure that I'm not working on the same function/module as some other people? Can I publish my intention some where to let other people know what I want to work on? As you can probably tell, I'm also new to open source development as well...

                               

                              Thanks.

                               

                              Brian

                      • Re: Bolt video on YouTube
                        bsp2020

                        Very interesting.

                        When I used VS2012, I only needed to add

                         

                        BOLT_CREATE_TYPENAME( bolt::cl::device_vector< char >::iterator );

                         

                        However, when I used VS2010, it game me run time compile error. I needed to add both of the lines. Not sure why... I'm not too familiar with C++ templates. So, I guess I have more studying to do...

                      • Re: Bolt video on YouTube
                        kknox

                        Hi bsp2020~  I apologize for my sluggish reply to your question; i'm on sabbatical now and not actively monitoring the forums.  jaidotsh is correct in that the 'hello world' code that i wrote in the video needs to be supplemented with an extra macro.

                        Thanks for the answer. They should have shown the correct code in that video. I wonder how he was able to compile and run that code without BOLT_CREATE_TYPENAME( bolt::cl::device_vector< char >::iterator );

                         

                        The reason is that I filmed these videos months prior to actually releasing them on the web, and the internals changed enough to break my sample code (The code to handle 'iterators' on the device was added after these videos filmed).  I really apologize for the confusion this caused you.

                         

                        There is actually a convenience macro provided in bolt to 'register' a new iterator type with bolt, based upon a previous definition.  It is BOLT_TEMPLATE_REGISTER_NEW_ITERATOR.  I provide below the complete sample source with how I would write it now:

                        // HelloWorld.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include  BOLT_FUNCTOR(StringFunctor, struct StringFunctor {     char operator() ( const char& in )     {         return in + 1;     }; }; ); BOLT_CREATE_TYPENAME( char ); BOLT_TEMPLATE_REGISTER_NEW_ITERATOR( bolt::cl::device_vector, int, char );

                        int _tmain(int argc, _TCHAR* argv[]) {     // Initialize and print an input string     std::string inputString( "GdkknVnqkc" );     std::cout << "input string: " << inputString << std::endl;     // Create input and ourput buffers     std::vector< char > inputVec( inputString.begin(), inputString.end() );     std::vector< char > outputVec( inputString.size() );     // This calls into OpenCL to do the work     bolt::cl::transform( inputVec.begin(), inputVec.end(), outputVec.begin(), StringFunctor( ) );     // trasfer data to host memory from device memory.     std::string outputString( outputVec.data(), outputVec.size() );     std::cout << "output string: " << outputString << std::endl;           return 0; }

                         

                        The first parameter to the macro is the templated container which contains an iterator type, which will be bolt::cl::device_vector for common uses.  The second parameter is a template type that has been previously 'registered' with Bolt, usually with BOLT_CREATE_CLCODE.  This is commonly an 'int' or 'float' as the most common used types in GPU programming.  The third parameter is the new type you want to register with Bolt, which will use the same template definition as the second parameter, but now works with the new type.  The second parameter has to be specified in the macro, because Bolt macros uses template specialization to query for the opencl string representation, and template specialization only works with fully concrete types, not templated types.  With template specialization, there is no guarantee that one template specialization looks anything at all like another template specialization (for instance, look at std::vector<bool> which is a classic example), so you have to specify to c++ the fully specified type in order for it to be able to instantiate a type, which we call a method on.

                         

                        I hope this helps your understanding, and again i apologize for my delayed response.

                         

                        Kent

                        1 of 1 people found this helpful