Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala Kernels can't handle branching #161

Open
yuvaldeg opened this issue Jan 27, 2020 · 1 comment
Open

Scala Kernels can't handle branching #161

yuvaldeg opened this issue Jan 27, 2020 · 1 comment
Labels
enhancement Adds new functionality

Comments

@yuvaldeg
Copy link

It seems like any code resulting in branching (if, for, while, etc...) will fail to generate.
If I avoid any branches, everything works completely fine and runs on my Mac's Radeon GPU.

Consider this simple example:

  @Test
  def failingCodeGen2(): Unit = {
    val size: Int = 500000
    val a: Array[Int] = (2 until size + 2).toArray

    val kernel = new Kernel() {
      override def run() {
        val gid = getGlobalId()
        val num = a(gid)
        var test = 1
        if (num % 2 == 0) {
          test = 2
        }
      }
    }
    kernel.execute(size)
    assert(kernel.getExecutionMode == EXECUTION_MODE.GPU)
  }

This code fails with:

com.aparapi.internal.exception.CodeGenException: goto -> 0026
	at com.aparapi.internal.writer.BlockWriter.writeInstruction(BlockWriter.java:751)
	at com.aparapi.internal.writer.KernelWriter.writeInstruction(KernelWriter.java:780)
	at com.aparapi.internal.writer.BlockWriter.writeSequence(BlockWriter.java:299)
	at com.aparapi.internal.writer.BlockWriter.writeBlock(BlockWriter.java:323)
	at com.aparapi.internal.writer.BlockWriter.writeMethodBody(BlockWriter.java:873)
	at com.aparapi.internal.writer.KernelWriter.write(KernelWriter.java:738)
	at com.aparapi.internal.writer.KernelWriter.writeToString(KernelWriter.java:792)
	at com.aparapi.internal.kernel.KernelRunner.executeInternalInner(KernelRunner.java:1535)
	at com.aparapi.internal.kernel.KernelRunner.executeInternalOuter(KernelRunner.java:1383)
	at com.aparapi.internal.kernel.KernelRunner.execute(KernelRunner.java:1374)
	at com.aparapi.Kernel.execute(Kernel.java:2897)
	at com.aparapi.Kernel.execute(Kernel.java:2854)
	at com.aparapi.Kernel.execute(Kernel.java:2829)
...
@freemo freemo added the enhancement Adds new functionality label Jan 29, 2020
@freemo
Copy link
Member

freemo commented Jan 29, 2020

Not all code structures are supported and scala is a bit less mature than java. Added as a to-do feature to look into

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adds new functionality
Projects
None yet
Development

No branches or pull requests

2 participants