C# 使用ResistentArrayGeneric的以下杂交程序代码有什么问题?
下面的代码从(图像)浮点数组中提取一个正方形选择,并将其放置在浮点数组2中。float2和原始数组都是表示图像中连续行的一维数组。原始浮点值放置在x字段中,y字段设置为零。 下面的代码无法使用Hybridizer编译,我不知道为什么。 其中一个错误是:- '不存在从“float”转换为“float2”的合适构造函数' 第32行 这是内核的右括号。 我没有直接从float转换到float2,所以我很困惑 有人知道怎么回事吗C# 使用ResistentArrayGeneric的以下杂交程序代码有什么问题?,c#,hybridizer,C#,Hybridizer,下面的代码从(图像)浮点数组中提取一个正方形选择,并将其放置在浮点数组2中。float2和原始数组都是表示图像中连续行的一维数组。原始浮点值放置在x字段中,y字段设置为零。 下面的代码无法使用Hybridizer编译,我不知道为什么。 其中一个错误是:- '不存在从“float”转换为“float2”的合适构造函数' 第32行 这是内核的右括号。 我没有直接从float转换到float2,所以我很困惑 有人知道怎么回事吗 using Hybridizer.Runtime.CUDAImports;
using Hybridizer.Runtime.CUDAImports;
using System;
namespace residentarraytest
{
class Program
{
[EntryPoint]
private static void ExtractArea(FloatResidentArray im,
ResidentArrayGeneric<int> roi,
ResidentArrayGeneric<float2> res)
{
int cp = roi[2] / 2;
int yPos = (1024 - roi[1]) - cp; // Y reversal just because...
int xPos = roi[0] - cp;
ExtractLoop(im, res, roi[2], yPos, xPos);
return;
}
[Kernel]
private static void ExtractLoop(FloatResidentArray im,
ResidentArrayGeneric<float2> res,
int size, int yPos, int xPos)
{
Parallel2D.For(0, size, 0, size, (y, x) =>
{
int i = x + y * size;
int j = x + xPos + (y + yPos) * size;
float2 tmp = new float2(im[j], 0f);
res[i] = tmp;
});
}
static void Main(string[] args)
{
ResidentArrayGeneric<int> roi = new ResidentArrayGeneric<int>(3);
roi[0] = 512; roi[1] = 512; roi[2] = 256;
FloatResidentArray im = new FloatResidentArray(1024 * 1024);
// im is filled with data here;
ResidentArrayGeneric<float2> res =
new ResidentArrayGeneric<float2>(roi[2] * roi[2]);
cudaDeviceProp prop;
cuda.GetDeviceProperties(out prop, 0);
HybRunner runner = HybRunner.Cuda();
// create a wrapper object to call GPU methods instead of C#
dynamic wrapped = runner.Wrap(new Program());
roi.RefreshDevice();
im.RefreshDevice();
res.RefreshDevice();
wrapped.ExtractArea(im, roi, res);
// program continues
Console.Out.WriteLine("DONE");
}
}
}
使用Hybridizer.Runtime.CUDAImports;
使用制度;
命名空间剩余数组测试
{
班级计划
{
[入口点]
私人静态空隙提取区(浮动居住区),
居住总投资回报率,
住宅(一般住宅)
{
int cp=投资回报率[2]/2;
int yPos=(1024-roi[1])-cp;//Y反转只是因为。。。
int xPos=roi[0]-cp;
提取循环(im、res、roi[2]、YPO、XPO);
返回;
}
[内核]
专用静态无效提取循环(FloatResidentArray im,
住宅区,
整数大小、整数ypo、整数xpo)
{
对于(0,大小,0,大小,(y,x)=>
{
int i=x+y*尺寸;
int j=x+xPos+(y+yPos)*大小;
float2 tmp=新的float2(im[j],0f);
res[i]=tmp;
});
}
静态void Main(字符串[]参数)
{
ResidentArrayGeneric roi=新ResidentArrayGeneric(3);
投资回报率[0]=512;投资回报率[1]=512;投资回报率[2]=256;
FloatResidentArray im=新的FloatResidentArray(1024*1024);
//im在这里充满了数据;
住宅总面积=
新住宅区(roi[2]*roi[2]);
cudaDeviceProp支柱;
cuda.GetDeviceProperties(输出属性,0);
HybRunner runner=HybRunner.Cuda();
//创建一个包装器对象来调用GPU方法而不是C#
dynamic wrapped=runner.wrapp(新程序());
RefreshDevice();
im.RefreshDevice();
resh.RefreshDevice();
提取区域(im、roi、res);
//节目继续
控制台输出写入线(“完成”);
}
}
}
您的代码没有问题。这是一个普通的杂交错误(在cuda接口中)
我在Altimesh中记录了一个问题
float2类型(内部驱动程序类型)没有将float作为参数的构造函数。你可以看一看
因此,不应公开C#构造函数float2::float2(x,y)
我们将在下一版本中公开函数make_float2
同时,您可以使用以下代码自己完成:
[IntrinsicFunction("make_float2")]
public static float2 make_float2(float x, float y)
{
return new float2(x, y);
}
[Kernel]
private static void ExtractLoop(FloatResidentArray im,
ResidentArrayGeneric<float2> res,
int size, int yPos, int xPos)
{
Parallel2D.For(0, size, 0, size, (y, x) =>
{
int i = x + y * size;
int j = x + xPos + (y + yPos) * size;
float2 tmp = make_float2(im[j], 0f);
res[i] = tmp;
});
}
[IntrinsicFunction(“make_float2”)]
公共静态浮点数2生成浮点数2(浮点数x,浮点数y)
{
返回新的浮动2(x,y);
}
[内核]
专用静态无效提取循环(FloatResidentArray im,
住宅区,
整数大小、整数ypo、整数xpo)
{
对于(0,大小,0,大小,(y,x)=>
{
int i=x+y*尺寸;
int j=x+xPos+(y+yPos)*大小;
float2 tmp=make_float2(im[j],0f);
res[i]=tmp;
});
}
您的代码没有问题。这是一个普通的杂交错误(在cuda接口中)
我在Altimesh中记录了一个问题
float2类型(内部驱动程序类型)没有将float作为参数的构造函数。你可以看一看
因此,不应公开C#构造函数float2::float2(x,y)
我们将在下一版本中公开函数make_float2
同时,您可以使用以下代码自己完成:
[IntrinsicFunction("make_float2")]
public static float2 make_float2(float x, float y)
{
return new float2(x, y);
}
[Kernel]
private static void ExtractLoop(FloatResidentArray im,
ResidentArrayGeneric<float2> res,
int size, int yPos, int xPos)
{
Parallel2D.For(0, size, 0, size, (y, x) =>
{
int i = x + y * size;
int j = x + xPos + (y + yPos) * size;
float2 tmp = make_float2(im[j], 0f);
res[i] = tmp;
});
}
[IntrinsicFunction(“make_float2”)]
公共静态浮点数2生成浮点数2(浮点数x,浮点数y)
{
返回新的浮动2(x,y);
}
[内核]
专用静态无效提取循环(FloatResidentArray im,
住宅区,
整数大小、整数ypo、整数xpo)
{
对于(0,大小,0,大小,(y,x)=>
{
int i=x+y*尺寸;
int j=x+xPos+(y+yPos)*大小;
float2 tmp=make_float2(im[j],0f);
res[i]=tmp;
});
}