Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#3339 closed defect (fixed)

ParModelica: Integer division does not work due to generated OpenCL-code not working

Reported by: Gustaf Thorslund Owned by: Mahder Alemseged Gebremedhin
Priority: normal Milestone: 1.9.4
Component: ParModelica Version: trunk
Keywords: Cc:

Description

As an attempt to work around #3335, or to get more threads from a parfor-loop, one may iterate over one range nx*ny and then unpack the x and y component using integer arithmetic. This, however, generates broken OpenCL-code for integer division. In the following code 'foo' is the test, while 'bar' is a not so nice workaround:

package DivTest
  constant Integer nx = 10;
  constant Integer ny = 10;
  
  function foo
    input Real a;
    output Real dst[nx,ny];
  protected
    parglobal Real parDst[nx,ny];
    parglobal Integer x;
    parglobal Integer y;
  algorithm
    parfor i in 1:nx*ny loop
      y := div((i-1), nx) + 1;
      x := i - (y-1) * nx;
      parDst[x,y] := x*y;
    end parfor;
    dst := parDst;
  end foo;

  function bar
    input Real a;
    output Real dst[nx,ny];
  protected
    Integer i2x[nx*ny];
    Integer i2y[nx*ny];
    parglobal Integer pi2x[nx*ny];
    parglobal Integer pi2y[nx*ny];
    parglobal Real parDst[nx,ny];
    parglobal Integer x;
    parglobal Integer y;
  algorithm
    for i in 1:nx, j in 1:ny loop
      i2x[i+(j-1)*nx] := i;
      i2y[i+(j-1)*nx] := j;
    end for;
    pi2x := i2x;
    pi2y := i2y;
    parfor i in 1:nx*ny loop
      y := pi2y[i];
      x := pi2x[i];
      parDst[x,y] := x*y;
    end parfor;
    dst := parDst;
  end bar;
end DivTest;

script:

setCommandLineOptions("+d=noevalfunc +g=ParModelica -v=1");
getErrorString();
loadFile("DivTest.mo");
getErrorString();

y:=DivTest.bar(4);
getErrorString();

x:=DivTest.foo(4);
getErrorString();

result:

.
 .
  .
- Select your device:      1
   :Using flags -I"/home/gusth/src/OpenModelica/build/include/omc/c/"
Error building program:
CL_BUILD_PROGRAM_FAILURE 
Build failed: Errors detected in compilation of OpenCL code:
CL_PROGRAM_BUILD_LOG:  
/tmp/OCLL5HGyT.cl(41): error: function "throwStreamPrint" declared implicitly
      if (tmp1 == 0) {throwStreamPrint(threadData, "Division by zero %s", "div(i + -1, 10)");}
                      ^

/tmp/OCLL5HGyT.cl(41): error: identifier "threadData" is undefined
      if (tmp1 == 0) {throwStreamPrint(threadData, "Division by zero %s", "div(i + -1, 10)");}
                                       ^

/tmp/OCLL5HGyT.cl(42): error: function "ldiv" declared implicitly
      _y = ((modelica_integer) 1 + ldiv(((modelica_integer)_i + (modelica_integer) -1),tmp1).quot);
                                   ^

/tmp/OCLL5HGyT.cl(42): error: expression must have struct or union type
      _y = ((modelica_integer) 1 + ldiv(((modelica_integer)_i + (modelica_integer) -1),tmp1).quot);
                                   ^

4 errors detected in the compilation of "/tmp/OCLL5HGyT.cl".

Internal error: clc compiler invocation failed.

Change History (6)

comment:1 by Gustaf Thorslund, 10 years ago

Owner: changed from Mahder Alemseged Gebremedhin to Gustaf Thorslund
Status: newaccepted

comment:2 by Gustaf Thorslund, 10 years ago

Owner: changed from Gustaf Thorslund to Mahder Alemseged Gebremedhin
Status: acceptedassigned

comment:3 by Mahder Alemseged Gebremedhin, 9 years ago

Resolution: fixed
Status: assignedclosed

comment:4 by Dietmar Winkler, 9 years ago

Milestone: Future1.9.4

Sorting these closed tickets away from "Future". Since they were closed after the last 1.9.3 release, it's very likely that they should have been part of the 1.9.4 release.

comment:5 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.4-1.9.x

Milestone renamed

comment:6 by Martin Sjölund, 9 years ago

Milestone: 1.9.4-1.9.x1.9.4

Milestone renamed

Note: See TracTickets for help on using tickets.