我正试图在jruby中使用Java Opencl,但遇到了一个我无法解决的问题,即使有很多谷歌搜索.
require 'java'
require 'JOCL-0.1.7.jar'
platforms = org.jocl.cl_platform_id.new
puts platforms.class
org.jocl.CL.clGetPlatformIDs(1, platforms, nil)
Run Code Online (Sandbox Code Playgroud)
当我使用以下命令运行此代码时:jruby test.rb当取消注释最后一行时,我收到以下错误:
#<Class:0x10191777e>
TypeError: cannot convert instance of class org.jruby.java.proxies.ConcreteJavaP
roxy to class [Lorg.jocl.cl_platform_id;
LukeTest at test.rb:29
(root) at test.rb:4
Run Code Online (Sandbox Code Playgroud)
只是想知道是否有人知道如何解决这个问题?
编辑:好吧所以我想通过使平台成为一个数组我已经解决了这个问题的第一部分:
platforms = org.jocl.cl_platform_id[1].new
Run Code Online (Sandbox Code Playgroud)
但是在添加下几行时会导致此错误:
context_properties = org.jocl.cl_context_properties.new()
context_properties.addProperty(org.jocl.CL::CL_CONTEXT_PLATFORM, platforms[0])
Run Code Online (Sandbox Code Playgroud)
CodegenUtils.java:98:in `human': java.lang.NullPointerException
from CodegenUtils.java:152:in `prettyParams'
from CallableSelector.java:462:in `argumentError'
from CallableSelector.java:436:in `argTypesDoNotMatch'
from RubyToJavaInvoker.java:248:in `findCallableArityTwo'
from InstanceMethodInvoker.java:66:in `call'
from CachingCallSite.java:332:in `cacheAndCall'
from CachingCallSite.java:203:in `call'
from test.rb:36:in `module__0$RUBY$LukeTest'
from test.rb:-1:in `module__0$RUBY$LukeTest'
from test.rb:4:in `__file__'
from test.rb:-1:in `load'
from Ruby.java:679:in `runScript'
from Ruby.java:672:in `runScript'
from Ruby.java:579:in `runNormally'
from Ruby.java:428:in `runFromMain'
from Main.java:278:in `doRunFromMain'
from Main.java:198:in `internalRun'
from Main.java:164:in `run'
from Main.java:148:in `run'
from Main.java:128:in `main'
Run Code Online (Sandbox Code Playgroud)
出于某种原因,当我打印平台类[0]时,它被列为NilClass!?
你忽略了一个非常简单的错误。你写
platforms = org.jocl.cl_platform_id.new
Run Code Online (Sandbox Code Playgroud)
但该行创建了该类的单个实例org.jocl.cl_platform_id。然后将其作为第二个参数传递给org.jocl.CL.clGetPlatformIDsin
org.jocl.CL.clGetPlatformIDs(1, platforms, nil)
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为该方法的第二个参数需要一个(空)对象数组org.jocl.cl_platform_id。
错误内容是:“我有一个 Java 对象的代理,但我无法按照org.jocl.cl_platform_id您的要求将其转换为对象数组。
如果你只是说
platforms = []
Run Code Online (Sandbox Code Playgroud)
并将其传递进去,它可能会起作用:)。