cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

oscarbarenys1
Adept II

Using inline assembly in OpenCL kernels (still not perfect)..

Hi,

much to my surprise is possible now to include asm() statements that include AMDIL instructions and that will pass down to AMDIL code generation..

still I'm not able to pass  variables to registers correctly:

this is similar to NV OCL

for example getting access to cycle counter:

    asm ("mov r2,Tmr2");

can work I think but using like:

int counter;

asm ("mov %0,Tmr2","=r"(counter));

doesn't work..

also related I'm asking if needing of op and arg modifiers to be set for example a line of OpenCL code has:

double r=a+b;

which seeing AMDIL code can be

dadd r1.xy__, r2.xyxy, r3.xyxy_neg(yw)

assuming inline asm works we need something like:

asm ("dadd r1, %0, %1": "d"(a), "d"(b) );

and op modifiers will be automatically  fixed or basically all modifiers like swizzling set i.e.:

asm ("dadd r1.xy__, %0.xyxy, %1.xyxy_neg(yw)": "d"(a), "d"(b) );

Many thanks..

0 Likes
4 Replies
himanshu_gautam
Grandmaster

Please note that inline assembly is un-supported territory and beats the whole purpose of OpenCL.

Usually when you write inline assembly code, and if you are destroying registers, you need to clearly specify what registers you are "clobbering". Hope you are doing that.

0 Likes
oscarbarenys1
Adept II

I'm sure I'm doing right since porting from NV opencl using inline assembly correctly.. would be a nice a sample in next SDK (like NV does) using inline assembly such as getting cycle counter register access for timing functions in GPU cycles

0 Likes

Having the ability to hack asm straight into OCL kernels sounds really useful. Is it possible to put in multi-line asm? The examples you gave are for single instructions?

btw Careful using the timer register as it is a very pure, global, cycle counter. Take a look at the IL spec to see what it truly represents and how it is affected by your kernel being swapped out, idled, etc.

0 Likes

Don't tested it.. all I want is to have access new instructions and registers so I don't seem to need multi-line asm.. as said AMD maybe add a sample to their sdk similar to NV or if you try can post here..

0 Likes