0

我想在 managedCuda 中使用字符串匹配。但是我怎样才能初始化它呢?

我试过使用 C# 版本,这里是例子:

stringAr = new List<string>();
        stringAr.Add("you");
        stringAr.Add("your");
        stringAr.Add("he");
        stringAr.Add("she");
        stringAr.Add("shes");

对于字符串匹配,我使用了以下代码:

bool found = false;
        for (int i = 0; i < stringAr.Count; i++)
        {
            found = (stringAr[i]).IndexOf(textBox2.Text) > -1;
            if (found) break;
        }
        if (found && textBox2.Text != "")
        {
            label1.Text = "Found!";
        }
        else
        {
            label1.Text = "Not Found!";
        }

我还在主机内存中分配输入 h_A

            string[] h_B = new string[N];

当我想在设备内存中分配并将向量从主机内存复制到设备内存时

        CudaDeviceVariable<string[]> d_B = h_B;

它给了我这个错误

The type 'string[]' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'CudaDeviceVariable<T>'

有什么帮助吗?

4

1 回答 1

1

根据文档和您的错误消息,只有不可为空的值类型可以与CudaDeviceVariable.

stringAr将列表更改为char[](或byte[])数组,然后使用CudaDeviceVariable通用参数 char(或 byte)在设备上分配它。

EDIT1 这是更改stringArbyte[]数组的代码:

byte[] stringArAsBytes = stringAr
                .SelectMany(s => System.Text.Encoding.ASCII.GetBytes(s))
                .ToArray();

然后尝试这样的事情:

CudaDeviceVariable<byte> d_data = stringArAsBytes;
于 2018-08-07T14:11:42.280 回答