mn416 / QPULib

Language and compiler for the Raspberry Pi GPU
Other
429 stars 64 forks source link

Feature Request: Enhancements on DSL #60

Open wimrijnders opened 6 years ago

wimrijnders commented 6 years ago

This are things I encountered during kernel development.

Operators

Given:

Int a;
Float b;
Float c;

... the following should work:

c = a+b;       // No operator for Int, Float combination
c = a*b;       // idem
a += 16;       // operator doesn't exist
c += b;        // operator doesn't exist
a = (b < 0);   // Can't assign result BoolExpr to Int

The first three have alternatives:

c = toFloat(a)+b;
c = toFloat(a)*b;
c = c + b;

...but I personally would truly appreciate it if the initial versions worked. I can sort of understand if you want to have explicit casts, but still.

Conversion of number values to DSL

I would appreciate the possibility to mix constants with DSL variables, for example:

 Int a = 1;
 Float b= 3.14f*radius;   // Also mix in expressions

Related, when using generator functions, it would be nice if a Float/Int can be initialized with a (C++) constant, just like with k.run():

void Generator(Int a, Float b, int c = 0, int d = 12.34f) { ... }
...
Generator(3, 2.78f);
Generator(valA, valB, 1, 24.68f);  // Also, pass in C++ values.

If that works like Where

I would like to see an If-operator that works like Where:

  Where (x > 10) x++; End

This works per vector element; if a given element satisfies the condition, the if-block is executed. Other elements are untouched.

Currently, Where only allows assignments and expressions. An If that works analogously, and which allows all statements, would be appreciated.

wimrijnders commented 6 years ago

Increment operator not working as expected

Kernel code:

void kernel(Ptr<Int> result) {
  Int outIndex = 0;
  result[outIndex++] = 0;

  // This works, of course
  // result[outIndex] = 0;
  // outIndex++;
}

Results in compile error:

error: no match for ‘operator[]’ (operand types are ‘QPULib::Ptr<QPULib::Int>’ and ‘void’)
   result[outIndex++] = 0;
         ^
wimrijnders commented 6 years ago

Question: What is the difference between Cond and BoolExpr?

When scanning their definition in the Library, they are practically identical. Can't they be combined?

I also encountered the following:

struct BoolExpr
{
  // Abstract syntax tree
  BExpr* bexpr;
  // Constructor
  BoolExpr(BExpr* b) { bexpr = b; }
  // Cast to Cond
  //operator Cond();     // <----- THIS commented out
};

This makes good sense to me and would nullify this question. Why is it commented out? Are there issues with it?