不正确地将cloo包含在C#中?
我试图让演示程序生成,但出现了此错误 我用mono和VisualStudio2010试过这个,同样的问题 该错误发生在第二行不正确地将cloo包含在C#中?,c#,.net,cloo,opencl.net,C#,.net,Cloo,Opencl.net,我试图让演示程序生成,但出现了此错误 我用mono和VisualStudio2010试过这个,同样的问题 该错误发生在第二行 program.Build(null, null, null, IntPtr.Zero); 编辑 C# 使用系统; 使用Cloo; 使用System.Collections.Concurrent; 使用System.Threading.Tasks; 使用System.IO; 名称空间克隆测试 { 类主类 { 公共静态void Main(字符串[]args) { //第
program.Build(null, null, null, IntPtr.Zero);
编辑
C#
使用系统;
使用Cloo;
使用System.Collections.Concurrent;
使用System.Threading.Tasks;
使用System.IO;
名称空间克隆测试
{
类主类
{
公共静态void Main(字符串[]args)
{
//第一站台
ComputePlatform platform=ComputePlatform.Platforms[0];
//使用所有gpu设备创建上下文
ComputeContext上下文=新的ComputeContext(ComputeDeviceTypes.Gpu,
新的ComputeContextPropertyList(平台),null,IntPtr.Zero);
//创建找到第一个gpu的命令队列
ComputeCommandQueue队列=新建ComputeCommandQueue
(
上下文
context.Devices[0],
ComputeCommandQueueFlags。无
);
//加载opencl源代码
StreamReader StreamReader=新的StreamReader(“kernels.cl”);
字符串clSource=streamReader.ReadToEnd();
streamReader.Close();
//使用opencl源代码创建程序
ComputeProgram=新的ComputeProgram(上下文,clSource);
//编译opencl源代码
Build(null,null,null,IntPtr.Zero);
//从程序加载所选内核
ComputeKernel kernel=program.CreateKernel(“helloWorld”);
//创建一个十整数数组及其长度
int[]message=newint[]{1,2,3,4,5};
int messageSize=message.Length;
//为消息分配内存缓冲区(int数组)
ComputeBuffer messageBuffer=新的ComputeBuffer(上下文,
ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.UseHostPointer,消息);
SetMemoryArgument(0,messageBuffer);//设置整数数组
SetValueArgument(1,messageSize);//设置数组大小
//执行内核
ExecuteTask(内核,null);
//等待完成
queue.Finish();
}
}
}
OpenCL
kernel void helloWorld(global read_only int* message, int messageSize) {
for (int i = 0; i < messageSize; i++) {
printf("%d", message[i]);
}
}
kernelvoid helloWorld(全局只读int*message,int messageSize){
for(int i=0;i
编辑
是的,打印可能不太受支持。我建议用一些简单的数字运算来表演你的“Hello world”。可能是这样的:
kernel void IncrementNumber(global float4 *celldata_in, global float4 *celldata_out) {
int index = get_global_id(0);
float4 a = celldata_in[index];
a.w = a.w + 1;
celldata_out[index] = a;
}
是的,打印可能不太受支持。我建议用一些简单的数字运算来表演你的“Hello world”。可能是这样的:
kernel void IncrementNumber(global float4 *celldata_in, global float4 *celldata_out) {
int index = get_global_id(0);
float4 a = celldata_in[index];
a.w = a.w + 1;
celldata_out[index] = a;
}
你的硬件支持openCL吗?我一直在通过openCL.net在那台计算机上使用openCL。我也想试试Cloo。OpenCL.Net似乎工作正常,还有什么我应该检查的吗?你的问题应该是“提供特定的代码来重现问题”,而不是指向clSource包含什么的示例的链接?我猜你过早地关闭了你的流。当我在那条麻烦的线路上遇到断点时,我添加了一个屏幕图像。clSource中似乎有正确的代码字符串您的硬件支持openCL吗?我一直通过openCL.net在那台计算机上使用openCL。我也想试试Cloo。OpenCL.Net似乎工作正常,还有什么我应该检查的吗?你的问题应该是“提供特定的代码来重现问题”,而不是指向clSource包含什么的示例的链接?我猜你过早地关闭了你的流。当我在那条麻烦的线路上遇到断点时,我添加了一个屏幕图像。clSource中似乎包含正确的代码字符串