gleisonsdm / DawnCC-Compiler

A source-to-source compiler for automatic parallelization of C programs through code annotation.
http://cuda.dcc.ufmg.br/dawn/
Other
60 stars 8 forks source link

SRA fails on small test with specific modula index array access #17

Open alexsusu opened 6 years ago

alexsusu commented 6 years ago

Hi. A somewhat important issue: SRA (at least the one at http://cuda.dcc.ufmg.br/dawn/index.php) isn't able to analyze the below program - I prefer using the MODULO macro with conditional statements (the other one below seems to work with SRA).

define SIZE 128

//typedef long TYPE; typedef int TYPE; //typedef short TYPE;

// Unfortunately, in C language: -1 % 4 = -1 //#define MODULO(val, SIZE) ((val < 0) ? (SIZE + val) : ((val >= SIZE) ? val - SIZE : val) ) // However, this macro WORKS with SRA: #define MODULO(val, SIZE) ((val + SIZE) % SIZE)

TYPE tmp[SIZE]; TYPE tmpF[SIZE];

//void Shift(TYPE tmp[SIZE], TYPE tmpF[SIZE], TYPE d) { void Shift(TYPE d) { TYPE k;

for (k = 0; k < SIZE; k++)
    tmpF[k] = tmp[MODULO(k + d, SIZE)];

}

gleisonsdm commented 6 years ago

Hi,

I tried to run this example in our webpage.

And using global variables: void Shift(TYPE d) {

Result: SRA cannot extract information based non-arithimetic expressions (as instructions like add, sub, mod, mul).

And using global variables: void Shift(TYPE d) {

Result: SRA works well.

Result: SRA fails for the same reason it fails in the first topic.

And using local variables: void Shift(TYPE tmp[SIZE], TYPE tmpF[SIZE], TYPE d) {

Result: SRA works well.

By the way, I thought in a solution to apply SRA to get positive modulo without using a ternary. Please, try to use the follow MODULO:

#define MODULO(val, SIZE) ((((val + SIZE) % SIZE) + SIZE) % SIZE)

Maybe this kind of trick can help you to run the program. I tried to run the program using the three pointer types:

I hope helped you. And thanks for your feedback.

Best Regards, Gleison