Fra*_*ani 4 python pyopengl pyopencl tensorflow pytorch
我想做的事:
我有一个脚本,用于分解给定范围内的素数:
# Python program to display all the prime numbers within an interval
lower = 900
upper = 1000
print("Prime numbers between", lower, "and", upper, "are:")
for num in range(lower, upper + 1):
# all prime numbers are greater than 1
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
print(num)
Run Code Online (Sandbox Code Playgroud)
我想使用 GPU 而不是 CPU 来运行这样的脚本,这样会更快
问题:
我的英特尔 NUC NUC8i7HVK上没有 NVIDIA GPU,而是“独立 GPU”
如果我运行此代码来检查我的 GPU 是什么:
import pyopencl as cl
import numpy as np
a = np.arange(32).astype(np.float32)
res = np.empty_like(a)
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)
mf = cl.mem_flags
a_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a)
dest_buf = cl.Buffer(ctx, mf.WRITE_ONLY, res.nbytes)
prg = cl.Program(ctx, """
__kernel void sq(__global const float *a,
__global float *c)
{
int gid = get_global_id(0);
c[gid] = a[gid] * a[gid];
}
""").build()
prg.sq(queue, a.shape, None, a_buf, dest_buf)
cl.enqueue_copy(queue, res, dest_buf)
print (a, res)
Run Code Online (Sandbox Code Playgroud)
我收到:
[0] <pyopencl.Platform 'AMD Accelerated Parallel Processing' at 0x7ffb3d492fd0>[1] <pyopencl.Platform 'Intel(R) OpenCL HD Graphics' at 0x187b648ed80>解决问题的可能方法:
我找到了一份指南,可以帮助您逐步了解如何在 GPU 上运行它。但是所有通过 GPU 传输 Python 的 Pyhton 库,如PyOpenGL、PyOpenCL、 Tensorflow (在 GPU 上强制执行 python 脚本))、PyTorch 等……都是为 NVIDIA 量身定制的。
如果您有 AMD,所有库都会要求ROCm,但据我所知,此类软件仍然不支持集成 GPU 或离散 GPU(请参阅下面我自己的回复)。
我只找到了一个讨论这种方法的指南,但我无法使其发挥作用。
是有希望还是我只是想做一些不可能的事情?
编辑:回复@chapelo
如果我选择的话,0回复是:
Set the environment variable PYOPENCL_CTX='0' to avoid being asked again.
[ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17.
18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31.] [ 0. 1. 4. 9. 16. 25. 36. 49. 64. 81. 100. 121. 144. 169.
196. 225. 256. 289. 324. 361. 400. 441. 484. 529. 576. 625. 676. 729.
784. 841. 900. 961.]
Run Code Online (Sandbox Code Playgroud)
如果我选择的话,1回复是:
Set the environment variable PYOPENCL_CTX='1' to avoid being asked again.
[ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17.
18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31.] [ 0. 1. 4. 9. 16. 25. 36. 49. 64. 81. 100. 121. 144. 169.
196. 225. 256. 289. 324. 361. 400. 441. 484. 529. 576. 625. 676. 729.
784. 841. 900. 961.]
Run Code Online (Sandbox Code Playgroud)
经过广泛的研究和多次尝试,我得出的结论是:
我安装了 ROCm,但如果运行rocminfo它会返回:
ROCk module is NOT loaded, possibly no GPU devices
Unable to open /dev/kfd read-write: No such file or directory
Failed to get user name to check for video group membership
hsa api call failure at: /src/rocminfo/rocminfo.cc:1142
Call returned HSA_STATUS_ERROR_OUT_OF_RESOURCES: The runtime failed to allocate the necessary resources. This error may also occur when the core runtime library needs to spawn threads or create internal OS-specific events.
Run Code Online (Sandbox Code Playgroud)
clinfo返回:
Number of platforms 1
Platform Name AMD Accelerated Parallel Processing
Platform Vendor Advanced Micro Devices, Inc.
Platform Version OpenCL 2.0 AMD-APP (3212.0)
Platform Profile FULL_PROFILE
Platform Extensions cl_khr_icd cl_amd_event_callback
Platform Extensions function suffix AMD
Platform Name AMD Accelerated Parallel Processing
Number of devices 0
NULL platform behavior
clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...) No platform
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...) No platform
clCreateContext(NULL, ...) [default] No platform
clCreateContext(NULL, ...) [other] No platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL) No devices found in platform
Run Code Online (Sandbox Code Playgroud)
rocm-smi返回:
Segmentation fault
Run Code Online (Sandbox Code Playgroud)
这是因为官方指南中说“Ryzen 的集成 GPU 不是 ROCm 的官方支持目标”。因为我的是集成 GPU,所以超出了范围。
我将不再浪费时间,可能会购买 NVIDIA 或 AMD eGPU(外部 GPU)
| 归档时间: |
|
| 查看次数: |
4066 次 |
| 最近记录: |