2013-08-21 73 views
2

我試圖比較字符串列表(每個列表中的元素數量巨大)。有人能幫我用cudafy嗎?我想在這種情況下,我應該使用鋸齒數組的字符,但我有一個CudafyCompileException - 表達式必須具有類類型(tried this approach)。它只適用於兩個字符串(char [])。所以,我有什麼想法我可以做到這一點?CUDA .Net比較字符串

2串代碼示例:

var km = CudafyTranslator.Cudafy(); 
_gpu = CudafyHost.GetDevice(); 
_gpu.LoadModule(km); 
var strFirst = "Hello, world"; 
var strSecond = "Hi world"; 
var devResult = _gpu.Allocate<char>(strFirst.Length); 
var first = strFirst.ToCharArray(); 
var second = strSecond.ToCharArray(); 
var result = new char[strFirst.Length]; 
var devFirst = _gpu.CopyToDevice(first); 
var devSecond = _gpu.CopyToDevice(second); 
_gpu.Launch(N, 1).CompareStrings(devFirst, devSecond, devResult); 
_gpu.CopyFromDevice(devResult, result); 
var hostStr = new string(result); 
Console.WriteLine(hostStr); 

而且方法本身:

[Cudafy] 
public static void CompareStrings(GThread thread, char[] c, char[] b, char[] result) 
{ 
    int tid = thread.blockIdx.x; 
    if (tid < c.Length) 
    { 
     if (c[tid] == b[tid]) 
     { 
      result[tid] = c[tid]; 
     } 
    } 
} 

回答

0
  • 代替c.Length傳遞長度作爲參數
  • 要小心,如果你的Unicode期運用字符,即2個字節