Bolt  1.1
C++ template library with support for OpenCL
Classes | Macros | Functions
ClCode: Traits and Helper Macros

Classes

struct  TypeName< TypeNameType >
 
struct  ClCode< Type >
 The definition of a type trait for the definition of a type, which could be arbitrarily complex. More...
 

Macros

#define STRINGIFY_CODE2(...)   #__VA_ARGS__
 Macro that wraps around arbitrary text, and creates a string out of it This macro is helpful to write inline OpenCL programs, as it avoids wrapping every line of OpenCL line with "XXX"
.
 
#define STRINGIFY_CODE(...)   STRINGIFY_CODE2( __VA_ARGS__ )
 
#define BOLT_CODE_STRING(...)   STRINGIFY_CODE( __VA_ARGS__ ); __VA_ARGS__;
 
#define BOLT_HOST_DEVICE_DEFINITION(...)   "namespace bolt { namespace cl {\n" STRINGIFY_CODE( __VA_ARGS__ ) "\n } } \n" ; __VA_ARGS__;
 
#define BOLT_CREATE_TYPENAME(Type)   template<> struct TypeName< Type > { static std::string get( ) { return #Type; } };
 
#define BOLT_CREATE_CLCODE(Type, CODE_STRING)
 
#define BOLT_TEMPLATE_REGISTER_NEW_TYPE(CONTAINER, OLDTYPE, NEWTYPE)
 This macro specializes a template with a new type using the template definition of a previously defined type This is a convenience macro to specialize a template for a new type, using the generic template definition from a previosly defined type.
 
#define BOLT_TEMPLATE_REGISTER_NEW_ITERATOR(CONTAINER, OLDTYPE, NEWTYPE)
 This macro specializes a template iterator with a new type using the template definition of a previously defined iterator type This is a convenience macro to specialize an iterator for a new type, using the generic template definition from a previosly defined iterator.
 
#define BOLT_CREATE_DEFINE(DefineName, D,...)
 
#define BOLT_FUNCTOR(T,...)
 
#define BOLT_TEMPLATE_FUNCTOR1(CONTAINER, TYPE1,...)
 
#define BOLT_TEMPLATE_FUNCTOR2(CONTAINER, TYPE1, TYPE2,...)
 
#define BOLT_TEMPLATE_FUNCTOR3(CONTAINER, TYPE1, TYPE2, TYPE3,...)
 
#define BOLT_TEMPLATE_FUNCTOR4(CONTAINER, TYPE1, TYPE2, TYPE3, TYPE4,...)
 
#define BOLT_CREATE_CODE_SNIPPET(Name,...)
 
#define BOLT_ADD_DEPENDENCY(Type, DependingType)   ClCode<Type>::addDependency(ClCode<DependingType>::get());
 

Functions

static std::string TypeName< TypeNameType >::get ()
 
static std::string ClCode< Type >::get ()
 

Detailed Description

Macro Definition Documentation

#define BOLT_ADD_DEPENDENCY (   Type,
  DependingType 
)    ClCode<Type>::addDependency(ClCode<DependingType>::get());

This macro is used to specify an A-depends-on-B type relationship between types. Bolt will ensure that whenever the definition of the A type is needed, the definition for the B type is also included

Parameters
TypeThe A type
DependingTypeThe B type
#define BOLT_CODE_STRING (   ...)    STRINGIFY_CODE( __VA_ARGS__ ); __VA_ARGS__;

Return a string with the specified function F, and also create code that is fed to the host compiler.

#define BOLT_CREATE_CLCODE (   Type,
  CODE_STRING 
)
Value:
template<> struct ClCode< Type > { static std::vector< std::string > dependencies;\
static void addDependency(std::string s) { dependencies.push_back(s); }; \
static std::string getDependingCodeString() { \
std::string c;\
for (std::vector< std::string >::iterator i = dependencies.begin(); i != dependencies.end(); i++) { c = c + *i; } \
return c; \
};\
static std::string getCodeString() { return CODE_STRING; }; \
static std::string get() { return getDependingCodeString() + getCodeString(); }; };\
__attribute__((weak)) std::vector< std::string > ClCode< Type >::dependencies;

Creates the ClCode trait that associates the specified type T with the string CODE_STRING.

Parameters
TypeA fully specified type name
CODE_STRINGThe definition of the type, which could be a template definition

An example:

// Manually create code string inline and associate with class IsOdd:
BOLT_CREATE_CLCODE(IsOdd, "struct IsOdd { bool operator(int val) { return val & 0x1; }; };"

Another approach is to define the code string in a file (so host and string are identical), then pass the string read from the file to BOLT_CREATE_CLCODE. (See clCodeFromFile)

#define BOLT_CREATE_CODE_SNIPPET (   Name,
  ... 
)
Value:
__VA_ARGS__;\
struct Name {};\
BOLT_CREATE_CLCODE(Name, std::string("#ifndef ") + std::string(#Name) +std::string(" \n") \
+ std::string("#define ") + std::string(#Name) + std::string(" \n") \
+ std::string(#__VA_ARGS__) + std::string(" \n") \
+ std::string("#endif \n"));

Registers code used on both host and device. It is used to help define complex relationships between user defined types, such as when one type contains instances of another. BOLT_CREATE_CODE_SNIPPET defines new types and BOLT_ADD_DEPENDENCY is used to specify the relationship to Bolt how the definition of one type relies on the definition of the other.

Parameters
NameAn identifier to associate with the trailing code
...Arbitrary user defined code
#define BOLT_CREATE_DEFINE (   DefineName,
  D,
  ... 
)
Value:
struct DefineName {}; BOLT_CREATE_CLCODE( DefineName, std::string("#ifndef ") + std::string(#D) + std::string(" \n")\
+ std::string("#define ") + std::string(#D) + std::string(" ") + std::string(#__VA_ARGS__) + std::string(" \n")\
+ std::string("#endif \n"));
#define BOLT_CREATE_TYPENAME (   Type)    template<> struct TypeName< Type > { static std::string get( ) { return #Type; } };

A convenience macro to create the TypeName trait for a specified class T.

Parameters
T: Class for which TypeName trait will be defined.
// Example that shows use of BOLT_CREATE_TYPENAME macro:
class MyClass { ... };
// Associate string "MyClass" with class MyClass

See TypeName for more information.

#define BOLT_FUNCTOR (   T,
  ... 
)
Value:
__VA_ARGS__; \
BOLT_CREATE_TYPENAME( T ); \
BOLT_CREATE_CLCODE( T, std::string("#ifndef ") + std::string("BOLT_FUNCTOR_") + std::string(#T) + std::string(" \n")\
+ std::string("#define ") + std::string("BOLT_FUNCTOR_") + std::string(#T) + std::string(" \n")\
+ std::string(#__VA_ARGS__) + std::string(" \n")\
+ std::string("#endif \n"));

Creates a string and a regular version of the functor F, and automatically defines the ClCode trait to associate the code string with the specified class T.

Parameters
TypeA fully specified type name
...Arbitrary type definition to associate with the type. See ClCodeTraits
#define BOLT_HOST_DEVICE_DEFINITION (   ...)    "namespace bolt { namespace cl {\n" STRINGIFY_CODE( __VA_ARGS__ ) "\n } } \n" ; __VA_ARGS__;

/brief Types that are defined within the bolt::cl namespace in host code should also be defined within the same namespace within the kernel code /detail This is a convenience macro, intended to only be used by the Bolt library itself, to wrap internal types in the appropriate bolt namespaces

#define BOLT_TEMPLATE_FUNCTOR1 (   CONTAINER,
  TYPE1,
  ... 
)
Value:
__VA_ARGS__; \
BOLT_CREATE_TYPENAME( CONTAINER<TYPE1> ) \
BOLT_CREATE_CLCODE( CONTAINER<TYPE1>, #__VA_ARGS__ )

Helper macro to define and specialize a template type for Bolt. The code given as the macro vararg should be a template container that requires 1 template paramter. The type passed into the TYPE1 argument is used to fully specialize the template container into a concrete type for Bolt.

Parameters
CONTAINERName to associate with the code given in the macro variable argument
TYPE1Type used to fully specialize the template code given in the macro variable argument
...Arbitrary user defined code; expected to be a 1 argument template type
#define BOLT_TEMPLATE_FUNCTOR2 (   CONTAINER,
  TYPE1,
  TYPE2,
  ... 
)
Value:
__VA_ARGS__; \
BOLT_CREATE_TYPENAME( CONTAINER<TYPE1> ) \
BOLT_CREATE_CLCODE( CONTAINER<TYPE1>, #__VA_ARGS__ ) \
BOLT_TEMPLATE_REGISTER_NEW_TYPE( CONTAINER, TYPE1, TYPE2 )

Helper macro to define and specialize a template type for Bolt. The code given as the macro vararg should be a template container that requires 1 template paramter. The types passed into TYPE1 & TYPE2 are used to fully specialize the template container into concrete types for Bolt use with two different types

Parameters
CONTAINERName to associate with the code given in the macro variable argument
TYPE1Type used to fully specialize the template code given in the macro variable argument
TYPE2Second type used to fully specialize the template code, independant of 1st type
...Arbitrary user defined code; expected to be a 1 argument template type
#define BOLT_TEMPLATE_FUNCTOR3 (   CONTAINER,
  TYPE1,
  TYPE2,
  TYPE3,
  ... 
)
Value:
__VA_ARGS__; \
BOLT_CREATE_TYPENAME( CONTAINER<TYPE1> ) \
BOLT_CREATE_CLCODE( CONTAINER<TYPE1>, #__VA_ARGS__ ) \
BOLT_TEMPLATE_REGISTER_NEW_TYPE( CONTAINER, TYPE1, TYPE2 ) \
BOLT_TEMPLATE_REGISTER_NEW_TYPE( CONTAINER, TYPE1, TYPE3 )

Helper macro to define and specialize a template type for Bolt. The code given as the macro vararg should be a template container that requires 1 template paramter. The types passed into TYPE1 & TYPE2 & TYPE3 are used to fully specialize the template container into concrete types for Bolt use with two different types

Parameters
CONTAINERName to associate with the code given in the macro variable argument
TYPE1Type used to fully specialize the template code given in the macro variable argument
TYPE2Second type used to fully specialize the template code , independant of other types
TYPE3Third type used to fully specialize the template code, independant of other types
...Arbitrary user defined code; expected to be a 1 argument template type
#define BOLT_TEMPLATE_FUNCTOR4 (   CONTAINER,
  TYPE1,
  TYPE2,
  TYPE3,
  TYPE4,
  ... 
)
Value:
__VA_ARGS__; \
BOLT_CREATE_TYPENAME( CONTAINER<TYPE1> ) \
BOLT_CREATE_CLCODE( CONTAINER<TYPE1>, #__VA_ARGS__ ) \
BOLT_TEMPLATE_REGISTER_NEW_TYPE( CONTAINER, TYPE1, TYPE2 ) \
BOLT_TEMPLATE_REGISTER_NEW_TYPE( CONTAINER, TYPE1, TYPE3 ) \
BOLT_TEMPLATE_REGISTER_NEW_TYPE( CONTAINER, TYPE1, TYPE4 )

Helper macro to define and specialize a template type for Bolt. The code given as the macro vararg should be a template container that requires 1 template paramter. The types passed into TYPE1 & TYPE2 & TYPE3 & type4 are used to fully specialize the template container into concrete types for Bolt use with two different types

Parameters
CONTAINERName to associate with the code given in the macro variable argument
TYPE1Type used to fully specialize the template code given in the macro variable argument
TYPE2Second type used to fully specialize the template code , independant of other types
TYPE3Third type used to fully specialize the template code, independant of other types
TYPE4Fourth type used to fully specialize the template code, independant of other types
...Arbitrary user defined code; expected to be a 1 argument template type
#define BOLT_TEMPLATE_REGISTER_NEW_ITERATOR (   CONTAINER,
  OLDTYPE,
  NEWTYPE 
)
Value:
BOLT_CREATE_TYPENAME( CONTAINER< NEWTYPE >::iterator ) \
BOLT_CREATE_CLCODE( CONTAINER< NEWTYPE >::iterator, ClCode< CONTAINER< OLDTYPE >::iterator >::get( ) )

This macro specializes a template iterator with a new type using the template definition of a previously defined iterator type This is a convenience macro to specialize an iterator for a new type, using the generic template definition from a previosly defined iterator.

Parameters
CONTAINERA template template parameter, such as std::vector without the type specified
OLDTYPEA type that has already been registered with the container template definition
NEWTYPEA new type to register with the template definition
#define BOLT_TEMPLATE_REGISTER_NEW_TYPE (   CONTAINER,
  OLDTYPE,
  NEWTYPE 
)
Value:
BOLT_CREATE_TYPENAME( CONTAINER< NEWTYPE > ) \
BOLT_CREATE_CLCODE( CONTAINER< NEWTYPE >, ClCode< CONTAINER< OLDTYPE > >::get( ) )

This macro specializes a template with a new type using the template definition of a previously defined type This is a convenience macro to specialize a template for a new type, using the generic template definition from a previosly defined type.

Parameters
CONTAINERA template template parameter, such as std::vector without the type specified
OLDTYPEA type that has already been registered with the container template definition
NEWTYPEA new type to register with the template definition
#define STRINGIFY_CODE2 (   ...)    #__VA_ARGS__

Macro that wraps around arbitrary text, and creates a string out of it This macro is helpful to write inline OpenCL programs, as it avoids wrapping every line of OpenCL line with "XXX"
.

Returns
The contents of the macro wrapped in an ASCII string