linux - 为什么我在 Linux 上从 mono 调用 opencl 库时出错?
问题描述
我在 ubuntu linux 下从 mono 调用 opencl 库时收到“对象引用未设置为对象实例”错误。
环境:
Ubuntu Linux 16.04
GeForce GTX 960
软件包:
ocl-icd-opencl-dev
nvidia-opencl-icd-384
opencl-headers
clinfo
mono-complete
从 /usr/lib/x86_64-linux-gnu 在 /usr/lib 中为 libOpenCL.so 创建了一个符号链接,因为它似乎不在单声道的路径中。
clinfo 看到平台并似乎为卡提供了正确的数据。
代码如下:
using cl_int = Int32;
using cl_uint = UInt32;
using cl_platform_id = IntPtr;
class Program
{
[DllImport("OpenCL.dll")]
public extern static cl_int clGetPlatformIDs(cl_uint num_entries, [Out] [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] cl_platform_id[] platforms, out cl_uint num_platforms);
static void Main(string[] args)
{
System.AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;
try
{
IntPtr[] platformIDs=null;
cl_int result=0;
cl_uint returnedPlatforms=0;
Console.WriteLine("call");
// determine how many platforms are available - call based in chronos docs.
// running with MONO_LOG_LEVEL=debug and MONO_LOG_MASK=dll shows the dll is found
// abends with 'object reference not set to an instance of an object'
result = (cl_int)clGetPlatformIDs(0, null, out returnedPlatforms);
Console.WriteLine(string.Format("ERR: {0} Platforms {1}", returnedPlatforms, result));
}
catch (Exception ex)
{
Console.WriteLine("Oops");
string stack = null;
StringBuilder sb = new StringBuilder();
while (ex != null)
{
sb.AppendLine(ex.Message);
if (ex.StackTrace != null && stack == null)
{
stack = ex.StackTrace;
}
ex = ex.InnerException;
}
if (stack != null)
sb.AppendLine(stack);
Console.WriteLine(sb.ToString());
}
Console.WriteLine("End");
}
static void UnhandledExceptionTrapper(object sender, UnhandledExceptionEventArgs e)
{
Console.WriteLine("Oops deep");
Console.WriteLine(e.ExceptionObject.ToString());
}
}
使用代码中所述的单声道调试集执行会导致:
call
Oops
Object reference not set to an instance of an object
at (wrapper managed-to-native) TestOCL.Program:clGetPlatformIDs (uint,intptr[],uint&)
at TestOCL.Program.Main (System.String[] args) <0x40740d60 + 0x000c7> in <filename unknown>:0
End
Mono: DllImport attempting to load: 'OpenCL.dll'.
Mono: DllImport error loading library
'/home/oxygen/configuration/libOpenCL.dll':
'/home/oxygen/configuration/libOpenCL.dll: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library '/home/oxygen/configuration/libOpenCL.dll.so': '/home/oxygen/configuration/libOpenCL.dll.so: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library '/usr/lib/libOpenCL.dll': '/usr/lib/libOpenCL.dll: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library '/usr/lib/libOpenCL.dll.so': '/usr/lib/libOpenCL.dll.so: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library 'libOpenCL.dll': 'libOpenCL.dll: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library 'libOpenCL.dll.so': 'libOpenCL.dll.so: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library 'OpenCL.dll': 'OpenCL.dll: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library '/home/oxygen/configuration/libOpenCL': '/home/oxygen/configuration/libOpenCL: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library '/home/oxygen/configuration/libOpenCL.so': '/home/oxygen/configuration/libOpenCL.so: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library '/usr/lib/libOpenCL': '/usr/lib/libOpenCL: cannot open shared object file: No such file or directory'.
Mono: DllImport loaded library '/usr/lib/libOpenCL.so'.
Mono: DllImport searching in: 'OpenCL.dll' ('/usr/lib/libOpenCL.so').
Mono: Searching for 'clGetPlatformIDs'.
Mono: Probing 'clGetPlatformIDs'.
Mono: Found as 'clGetPlatformIDs'.
“对象引用未设置为对象的实例”在正常的异常处理中被捕获。
该调用尝试获取可用平台的数量并遵循 Khronos 文档。
我找不到它不起作用的任何原因,也找不到对类似问题的引用。有人可以提供方向/解决方案吗?
解决方案
推荐阅读
- python - 从Python中的字典中检索第一个键值对而不使用列表,iter
- python - 如何在 Python 中创建可变代码?
- python - 如何让 Django 使用当前应用程序的模板文件夹?
- json - Couchbase 中的索引 - 使用主索引而不是二级索引
- javascript - 如何以及何时检查数组中的所有对象值是否不为空?
- swift - Swift 闭包定义为类属性不能访问其他类属性
- react-native - React Navigation - 当我在屏幕之间导航时内存增加
- javascript - 我能够检查隐藏类型变量,但我收到通过 JS 将 HTML 表单的输入类型隐藏变量发送到 PHP 文件的错误
- java - HikariCP 与 JDBC 指标 Spring Boot2
- python - 如何循环遍历每个源文件并将特定列复制到新工作簿中,每个新的“粘贴”转移到相邻列?