#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 , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → accepted |
comment:2 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | accepted → assigned |
comment:3 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:4 by , 9 years ago
Milestone: | Future → 1.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.
Note:
See TracTickets
for help on using tickets.
Fixed in a481fe6a68354f9395f8d0e6c579079d035a0dd7/OMCompiler.
Test added in a243f9eb9b3638c7b233edbe1ad27a479af3db58/OpenModelica-testsuite