我已将 Haskell 应用程序移植到 CUDA 以加速它。现在,我有一个.cu文件想要从 Haskell 作为 API 调用。我已经通过遵循教程轻松地管理了 FFI C 文件,但我不确定这如何应用于 CUDA/nvcc。如何通过 FFI 访问 CUDA 源文件中定义的符号?
为了完成,这就是我尝试将其视为.cu普通.c文件的内容:
vh:CUDA apple1$ nvcc hello.cu -c -o hello.o
vh:CUDA apple1$ ghc test.hs -o test hello.o
Linking test ...
Undefined symbols for architecture x86_64:
"___cudaRegisterFatBinary", referenced from:
__sti____cudaRegisterAll_40_tmpxft_00002168_00000000_7_hello_cpp1_ii_f33df8d2() in hello.o
"___cudaRegisterFunction", referenced from:
__nv_cudaEntityRegisterCallback(void**) in hello.o
"___cudaUnregisterFatBinary", referenced from:
__cudaUnregisterBinaryUtil() in hello.o
"_cudaConfigureCall", referenced from:
render(Renderer_*) in hello.o
"_cudaFree", referenced from:
renderer_free(Renderer_*) in hello.o
"_cudaLaunch", referenced from:
cudaError …Run Code Online (Sandbox Code Playgroud) 我正在阅读“使用 fastai 和 PyTorch 为编码人员进行深度学习”一书。对于 Embedding 模块的作用,我仍然有些困惑。它似乎是一个简短而简单的网络,但我似乎无法理解 Embedding 与没有偏见的 Linear 的不同之处。我知道它做了一些更快的点积计算版本,其中一个矩阵是一个单热编码矩阵,另一个是嵌入矩阵。这样做实际上是为了选择一条数据?请指出我错在哪里。这是书中展示的简单网络之一。
class DotProduct(Module):
def __init__(self, n_users, n_movies, n_factors):
self.user_factors = Embedding(n_users, n_factors)
self.movie_factors = Embedding(n_movies, n_factors)
def forward(self, x):
users = self.user_factors(x[:,0])
movies = self.movie_factors(x[:,1])
return (users * movies).sum(dim=1)
Run Code Online (Sandbox Code Playgroud)