Syncleus / aparapi

The New Official Aparapi: a framework for executing native Java and Scala code on the GPU.
http://aparapi.com
Apache License 2.0
465 stars 59 forks source link

Support for scala #130

Closed eklavya closed 6 years ago

eklavya commented 6 years ago

Scala generated bytecode is not supported yet.

Example project: https://github.com/eklavya/OpenCLWB

https://github.com/eklavya/OpenCLWB/blob/master/src/main/scala/Main.scala#L37-L38 switches between scala and java kernels.

Code:

val bestDevice: Device = KernelManager.instance.bestDevice
  val range: Range = Range.create(bestDevice.getMaxWorkItemSize()(0), bestDevice.getMaxWorkGroupSize)

  def testKernel(inA: Array[Float], inB: Array[Float]): Array[Float] = {
    val result = new Array[Float](inA.length)
    val kernel = new Kernel() {
      override def run() {
        val i = getGlobalId()
        result(i) = ((inA(i) + inB(i)) / (inA(i) / inB(i))) * ((inA(i) - inB(i)) / (inA(i) * inB(i))) -
          ((inB(i) - inA(i)) * (inB(i) + inA(i))) * ((inB(i) - inA(i)) / (inB(i) * inA(i)))
      }
    }

    kernel.execute(range)
    result
  }

Log:

[info] Detected best opencl device is a GPU
[info] Detected best opencl device: Apple<GPU>
[error] Jun 07, 2018 1:21:07 PM com.aparapi.internal.model.ClassModel$AttributePool <init>
[error] WARNING: Found unexpected Attribute (name = MethodParameters)
[error] Jun 07, 2018 1:21:07 PM com.aparapi.internal.model.ClassModel$AttributePool <init>
[error] WARNING: Found unexpected Attribute (name = ScalaInlineInfo)
[error] Jun 07, 2018 1:21:07 PM com.aparapi.internal.model.ClassModel$AttributePool <init>
[error] WARNING: Found unexpected Attribute (name = Scala)
[error] clBuildProgram failed
[error] ************************************************
[error] <program source>:7:5: warning: no previous prototype for function 'get_pass_id'
[error] int get_pass_id(This *this){
[error]     ^
[error] <program source>:24:10: error: use of undeclared identifier 'i'
[error]          i = get_global_id(0);
[error]          ^
[error] <program source>:25:25: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                         ^
[error] <program source>:25:46: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                              ^
[error] <program source>:25:63: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                               ^
[error] <program source>:25:82: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                  ^
[error] <program source>:25:99: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                   ^
[error] <program source>:25:120: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                        ^
[error] <program source>:25:137: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                         ^
[error] <program source>:25:156: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                            ^
[error] <program source>:25:173: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                             ^
[error] <program source>:25:196: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                                                    ^
[error] <program source>:25:213: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                                                                     ^
[error] <program source>:25:232: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                                                                                        ^
[error] <program source>:25:249: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                                                                                                         ^
[error] <program source>:25:270: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                                                                                                                              ^
[error] <program source>:25:287: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                                                                                                                                               ^
[error] <program source>:25:306: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                                                                                                                                                                  ^
[error] <program source>:25:323: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                                                                                                                                                                                   ^
[error] ************************************************
[error] Jun 07, 2018 1:21:07 PM com.aparapi.internal.kernel.KernelRunner fallBackToNextDevice
[error] WARNING: Device failed for anon$1, devices={Apple<GPU>|Apple<CPU>|Java Alternative Algorithm|Java Thread Pool}: OpenCL compile failed
[error] com.aparapi.internal.exception.AparapiException: OpenCL compile failed
[error]     at com.aparapi.internal.kernel.KernelRunner.fallBackToNextDevice(KernelRunner.java:1318)
[error]     at com.aparapi.internal.kernel.KernelRunner.executeInternalInner(KernelRunner.java:1582)
[error]     at com.aparapi.internal.kernel.KernelRunner.executeInternalOuter(KernelRunner.java:1383)
[error]     at com.aparapi.internal.kernel.KernelRunner.execute(KernelRunner.java:1374)
[error]     at com.aparapi.Kernel.execute(Kernel.java:2897)
[error]     at com.aparapi.Kernel.execute(Kernel.java:2854)
[error]     at com.aparapi.Kernel.execute(Kernel.java:2794)
[error]     at Main$.testKernel(Main.scala:23)
[error]     at Main$.$anonfun$main$3(Main.scala:38)
[error]     at scala.runtime.java8.JFunction1$mcJI$sp.apply(JFunction1$mcJI$sp.java:12)
[error]     at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
[error]     at scala.collection.immutable.Range.foreach(Range.scala:156)
[error]     at scala.collection.TraversableLike.map(TraversableLike.scala:234)
[error]     at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
[error]     at scala.collection.AbstractTraversable.map(Traversable.scala:104)
[error]     at Main$.main(Main.scala:35)
[error]     at Main.main(Main.scala)
[error] Jun 07, 2018 1:21:07 PM com.aparapi.internal.kernel.KernelRunner fallBackToNextDevice
[error] WARNING: Trying next device: Apple<CPU>
[error] clBuildProgram failed
[error] ************************************************
[error] <program source>:7:5: warning: no previous prototype for function 'get_pass_id'
[error] int get_pass_id(This *this){
[error]     ^
[error] <program source>:24:10: error: use of undeclared identifier 'i'
[error]          i = get_global_id(0);
[error]          ^
[error] <program source>:25:25: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                         ^
[error] <program source>:25:46: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                              ^
[error] <program source>:25:63: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                               ^
[error] <program source>:25:82: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                  ^
[error] <program source>:25:99: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                   ^
[error] <program source>:25:120: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                        ^
[error] <program source>:25:137: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                         ^
[error] <program source>:25:156: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                            ^
[error] <program source>:25:173: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                             ^
[error] <program source>:25:196: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                                                    ^
[error] <program source>:25:213: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                                                                     ^
[error] <program source>:25:232: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                                                                                        ^
[error] <program source>:25:249: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                                                                                                         ^
[error] <program source>:25:270: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                                                                                                                              ^
[error] <program source>:25:287: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                                                                                                                                               ^
[error] <program source>:25:306: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                                                                                                                                                                  ^
[error] <program source>:25:323: error: use of undeclared identifier 'i'
[error]          this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
[error]                                                                                                                                                                                                                                                                                                                                   ^
[error] ************************************************
[error] Jun 07, 2018 1:21:08 PM com.aparapi.internal.kernel.KernelRunner fallBackToNextDevice
[error] WARNING: Device failed for anon$1, devices={Apple<CPU>|Java Alternative Algorithm|Java Thread Pool}: OpenCL compile failed
[error] com.aparapi.internal.exception.AparapiException: OpenCL compile failed
[error]     at com.aparapi.internal.kernel.KernelRunner.fallBackToNextDevice(KernelRunner.java:1318)
[error]     at com.aparapi.internal.kernel.KernelRunner.executeInternalInner(KernelRunner.java:1582)
[error]     at com.aparapi.internal.kernel.KernelRunner.fallBackToNextDevice(KernelRunner.java:1361)
[error]     at com.aparapi.internal.kernel.KernelRunner.fallBackToNextDevice(KernelRunner.java:1323)
[error]     at com.aparapi.internal.kernel.KernelRunner.fallBackToNextDevice(KernelRunner.java:1318)
[error]     at com.aparapi.internal.kernel.KernelRunner.executeInternalInner(KernelRunner.java:1582)
[error]     at com.aparapi.internal.kernel.KernelRunner.executeInternalOuter(KernelRunner.java:1383)
[error]     at com.aparapi.internal.kernel.KernelRunner.execute(KernelRunner.java:1374)
[error]     at com.aparapi.Kernel.execute(Kernel.java:2897)
[error]     at com.aparapi.Kernel.execute(Kernel.java:2854)
[error]     at com.aparapi.Kernel.execute(Kernel.java:2794)
[error]     at Main$.testKernel(Main.scala:23)
[error]     at Main$.$anonfun$main$3(Main.scala:38)
[error]     at scala.runtime.java8.JFunction1$mcJI$sp.apply(JFunction1$mcJI$sp.java:12)
[error]     at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
[error]     at scala.collection.immutable.Range.foreach(Range.scala:156)
[error]     at scala.collection.TraversableLike.map(TraversableLike.scala:234)
[error]     at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
[error]     at scala.collection.AbstractTraversable.map(Traversable.scala:104)
[error]     at Main$.main(Main.scala:35)
[error]     at Main.main(Main.scala)
[error] Jun 07, 2018 1:21:08 PM com.aparapi.internal.kernel.KernelRunner fallBackToNextDevice
[error] WARNING: Trying next device: Java Alternative Algorithm
[info] GPU Time: 446735153
[info] CPU Time: 2368001679
eklavya commented 6 years ago

Class files from the example. classes.zip

eklavya commented 6 years ago

Initially it didn't work at all with aparapi and failed with NPE, to fix that NPE and get the above mentioned log I had to change com.aparapi.internal.instruction.Instruction which needs to have:

final Instruction j = i.getRootExpr().getPrevExpr();
final Instruction startInstruction =  j == null ? i : j;

on lines 816-817

eklavya commented 6 years ago

Generated OpenCL code in case of scala kernel:

typedef struct This_s{
   __global float *result$1;
   __global float *inA$1;
   __global float *inB$1;
   int passid;
}This;
int get_pass_id(This *this){
   return this->passid;
}
__kernel void run(
   __global float *result$1,
   __global float *inA$1,
   __global float *inB$1,
   int passid
){
   This thisStruct;
   This* this=&thisStruct;
   this->result$1 = result$1;
   this->inA$1 = inA$1;
   this->inB$1 = inB$1;
   this->passid = passid;
   {
      {
         i = get_global_id(0);
         this->result$1[i]  = (((this->inA$1[i] + this->inB$1[i]) / (this->inA$1[i] / this->inB$1[i])) * ((this->inA$1[i] - this->inB$1[i]) / (this->inA$1[i] * this->inB$1[i]))) - (((this->inB$1[i] - this->inA$1[i]) * (this->inB$1[i] + this->inA$1[i])) * ((this->inB$1[i] - this->inA$1[i]) / (this->inB$1[i] * this->inA$1[i])));
      }
      return;
   }
}

In case of java kernel:

typedef struct This_s{
   __global float *val$result;
   __global float *val$inA;
   __global float *val$inB;
   int passid;
}This;
int get_pass_id(This *this){
   return this->passid;
}
__kernel void run(
   __global float *val$result,
   __global float *val$inA,
   __global float *val$inB,
   int passid
){
   This thisStruct;
   This* this=&thisStruct;
   this->val$result = val$result;
   this->val$inA = val$inA;
   this->val$inB = val$inB;
   this->passid = passid;
   {
      int i_1 = get_global_id(0);
      this->val$result[i_1]  = (((this->val$inA[i_1] + this->val$inB[i_1]) / (this->val$inA[i_1] / this->val$inB[i_1])) * ((this->val$inA[i_1] - this->val$inB[i_1]) / (this->val$inA[i_1] * this->val$inB[i_1]))) - (((this->val$inB[i_1] - this->val$inA[i_1]) * (this->val$inB[i_1] + this->val$inA[i_1])) * ((this->val$inB[i_1] - this->val$inA[i_1]) / (this->val$inB[i_1] * this->val$inA[i_1])));
      return;
   }
}