我正在尝试编译并运行CUDA脚本。
我的环境是:
C:\Temp\CUDA>python --version
Python 3.6.3 :: Anaconda custom (64-bit)
C:\Temp\CUDA>python --version accelerate
Python 3.6.3 :: Anaconda custom (64-bit)
C:\Temp\CUDA>python --version cuda_toolki
Python 3.6.3 :: Anaconda custom (64-bit)
我正在尝试编译的python脚本是:
from numba.pycc import CC
import numpy as np
import time
cc = CC('VectorAdd')
def VectorAdd(a, b):
return a + b
def main():
N = 32000000
A = np.ones(N, dtype=np.float32)
B = np.ones(N, dtype=np.float32)
start = time.time()
C = VectorAdd(A, B)
vector_add_time = time.time() - start
print("C[:5] = " + str(C[:5]))
print("C[-5:] = " + str(C[-5:]))
print("VectorAdd took % seconds" % vector_add_time)
if __name__ == '__main__':
cc.compile()
这产生了文件:
VectorAddcp36-win-amd64.pyd
在我的目录中。然后我运行了脚本:
import VectorAdd
def main():
VectorAdd.main()
if __name__ == '__main__':
main()
执行main方法,我得到了:
C:\Temp\CUDA>python VectorAdd_run_pyd.py
Traceback (most recent call last):
File "VectorAdd_run_pyd.py", line 7, in <module>
main()
File "VectorAdd_run_pyd.py", line 4, in main
VectorAdd.main()
AttributeError: module 'VectorAdd' has no attribute 'main'
我做错了什么?
查尔斯