private void HandleError(cudaError error) { if (error != cudaError.cudaSuccess) { throw new CudafyHostException(error.ToString()); } }
public void nppsSet_32s_test() { int length = 1024; int value = 75; IntPtr ptr = Npps.nppsMalloc_32s(length); int[] result = new int[length]; GCHandle gcHandle = GCHandle.Alloc(result, GCHandleType.Pinned); IntPtr h_result = Marshal.UnsafeAddrOfPinnedArrayElement(result, 0); UInt64 size = Convert.ToUInt64(sizeof(int) * result.Length); NppStatus status = Npps.nppsSet_32s(value, ptr, length); if (status != NppStatus.NPP_SUCCESS) { Assert.Fail(String.Format("Fail {0}", status.ToString())); } cudaError cudaStatus = CudaRuntimeApi.cudaMemcpy(h_result, ptr, size, cudaMemcpyKind.DeviceToHost); if (cudaStatus != cudaError.cudaSuccess) { Assert.Fail(String.Format("Fail {0}", cudaStatus.ToString())); } for (int i = 0; i < result.Length; i++) { Assert.AreEqual(value, result[i]); } gcHandle.Free(); Npps.nppsFree(ptr); }
public static void Check(cudaError error, string message) { if (error != cudaError.cudaSuccess) { message = string.Format("{0}: {1}", error.ToString(), message); Exception exception = new CudaException(message); exception.Data.Add("cudaError", error); throw exception; } }
private void CopyFromDevice <T>(Array devArray, int devOffset, Array hostArray, int hostOffset, int count) { CUDevicePtrEx devPtrEx = GetDeviceMemory(devArray) as CUDevicePtrEx; int n = hostArray.Length; Type type = typeof(T); int elemSize = CUDA.MSizeOf(type); unsafe { GCHandle handle = GCHandle.Alloc(hostArray, GCHandleType.Pinned); IntPtr hostPtr = new IntPtr(handle.AddrOfPinnedObject().ToInt64() + hostOffset * elemSize); CUdeviceptr devPtr = devPtrEx.DevPtr + devOffset * elemSize; cudaError rc = CUDARuntime.cudaMemcpy(hostPtr, devPtr, elemSize * n, cudaMemcpyKind.cudaMemcpyDeviceToHost); handle.Free(); HandleError(rc); } }
public static extern string cudaGetErrorString(cudaError error);