Software Archive
Read-only legacy content
17061 Discussions

how to conditionally compile pragma and cilk code respectively?

King_Crimson
Beginner
441 Views

My code has two versions, one using the pragma offload, the other using cilk offload. Now I want to simplify the codes such that the common functions and constants  are put in the same files. Can this be achieved through conditional compilation? Something like:

#if MACRO_PRAGMA

#pragma offload_attribute(push,target(mic))

#else //MACRO_CILK

#pragma offload_attribute(push,_Cilk_shared)

#endif

Besides, what is the point of inventing two types of key words, target(mic) and _Cilk_shared, as the parameter of the offload_attribute. From my naive thought, doesn't target(mic) alone suffice? Thanks for explanation.

 

 

0 Kudos
1 Solution
James_C_Intel2
Employee
441 Views

Personally, I am a fan of using _Pragma for things like this, since then you can isolate the conditional behaviour in one place, and not have all of your code full of #if ... #else ... #endif noise.
So I'd be tempted to do something like (typed into this post, so not compiled :-))

[cpp]

#if SIMPLE_OFFLOAD
# define OFFLOAD_START _Pragma("offload_attribute(push,target(mic))")
# define OFFLOAD_END _Pragma("offload_attribute(pop)")
#elif CILK_OFFLOAD
# define OFFLOAD_START _Pragma("offload_attribute(push,_Cilk_shared))")
# define OFFLOAD_END _Pragma("offload_attribute(pop)")
#else
# define OFFLOAD_START
# define OFFLOAD_END
#endif
[/cpp]

Then you can ust use OFFLOAD_START and OFFLOAD_END in your code, choosing which offload style to do in one place.

View solution in original post

0 Kudos
2 Replies
James_C_Intel2
Employee
442 Views

Personally, I am a fan of using _Pragma for things like this, since then you can isolate the conditional behaviour in one place, and not have all of your code full of #if ... #else ... #endif noise.
So I'd be tempted to do something like (typed into this post, so not compiled :-))

[cpp]

#if SIMPLE_OFFLOAD
# define OFFLOAD_START _Pragma("offload_attribute(push,target(mic))")
# define OFFLOAD_END _Pragma("offload_attribute(pop)")
#elif CILK_OFFLOAD
# define OFFLOAD_START _Pragma("offload_attribute(push,_Cilk_shared))")
# define OFFLOAD_END _Pragma("offload_attribute(pop)")
#else
# define OFFLOAD_START
# define OFFLOAD_END
#endif
[/cpp]

Then you can ust use OFFLOAD_START and OFFLOAD_END in your code, choosing which offload style to do in one place.

0 Kudos
Ravi_N_Intel
Employee
441 Views

The implementation for _Cilk_shared and pragma using target(mic) attribute are different.  The compiler and runtime library (without going into details)  generates additional information in shared memory for functions marked with _Cilk_shared to enable lookup during offload calls using _Cilk_offload.

0 Kudos
Reply