我只是想问一下,如果有人能够让我了解在使用几个简单的内核之后要注意什么.
我可以使用相同的CommandQueue
吗?我可以用不同的方式运行几次clCreateProgramWithSource
+ 吗?我忘记了什么?cl_program
cl_program
谢谢!
我为两个矩阵的元素乘法构建了一个内核,但至少在我的配置中,当每个矩阵大于2GB时,我的OpenCL内核只会更快.所以我想知道,如果是因为我的天真内核(见下文)或者因为元素操作的本质,这意味着元素操作不会因使用GPU而获益.
感谢您的输入!
核心:
KERNEL_CODE = """
// elementwise multiplication: C = A .* B.
__kernel void matrixMul(
__global float* C,
__global float* A,
__global float* B,
int width, int height)
{
// ID
int x = get_global_id(0);
int y = get_global_id(1);
// Multiplying
C[y * height + x ] = A[y * height + x] * B[y * height + x];
}
"""
Run Code Online (Sandbox Code Playgroud)
ps我读了一些专家认为,CUDA与OpenCL有太大的不同,无法在同一个问题中回答这两个问题,可以自由地从标题和标签中删除它.
有没有人有NavigationController.PopToViewContoller();
使用MonoTouch/Xamarin 的例子?
我不明白以下几行到底发生了什么:
unsigned char *membershipChanged = (unsigned char *)sharedMemory;
Run Code Online (Sandbox Code Playgroud)
float *clusters = (float *)(sharedMemory + blockDim.x);
Run Code Online (Sandbox Code Playgroud)
我假设 in #1sharedMemory
有效地重命名为membershipChanged
,但为什么要将 the 添加blockDim
到sharedMemory
指针中。这个地址指向哪里?
sharedMemory
创建于 extern __shared__ char sharedMemory[];
我在CUDA kmeans 实现中找到的代码。
void find_nearest_cluster(int numCoords,
int numObjs,
int numClusters,
float *objects, // [numCoords][numObjs]
float *deviceClusters, // [numCoords][numClusters]
int *membership, // [numObjs]
int *intermediates)
{
extern __shared__ char sharedMemory[];
// The type chosen for membershipChanged must be large enough to support
// reductions! There are …
Run Code Online (Sandbox Code Playgroud) 为了加快我的代码,我正在将一个多维的sumproduct函数从Python转换为Theano.我的Theano代码达到了相同的结果,但是一次只计算一个维度的结果,因此我必须使用Python for循环来获得最终结果.我认为这会使代码变慢,因为Theano无法在多个函数调用之间优化内存使用和传输(对于gpu).或者这是一个错误的假设?
那么如何更改Theano代码,以便在一个函数调用中计算sumprod?
原始的Python函数:
def sumprod(a1, a2):
"""Sum the element-wise products of the `a1` and `a2`."""
result = numpy.zeros_like(a1[0])
for i, j in zip(a1, a2):
result += i*j
return result
Run Code Online (Sandbox Code Playgroud)
对于以下输入
a1 = ([1, 2, 4], [5, 6, 7])
a2 = ([1, 2, 4], [5, 6, 7])
Run Code Online (Sandbox Code Playgroud)
输出将是:[ 26. 40. 65.]
即1*1 + 5*5,2*2 + 6*6和4*4 + 7*7
Theano版本的代码:
import theano
import theano.tensor as T
import numpy
a1 = ([1, 2, 4], [5, 6, 7])
a2 = ([1, 2, …
Run Code Online (Sandbox Code Playgroud) [更新]如何输出警告信息compiler.SourceModule(kernel_code)
?在@flipchart的帮助下,我能够通过PyCUDA将正确的参数传递给NVCC,但我仍然不知道,在哪里可以访问编译器警告.
[原始问题]
直接使用NVCC可以使用编译器开关-Wall
*.如何在pycuda中存档?
我试过mod = compiler.SourceModule(kernel_code,options=['-Wall'])
,但错误消息指出:
pytools.prefork.ExecError: error invoking 'nvcc --cubin -Wall -arch sm_11 -I/usr/local/lib/python2.6/dist-packages/pycuda-0.94.2-py2.6-linux-x86_64.egg/pycuda/../include/pycuda kernel.cu': status 255 invoking 'nvcc --cubin -Wall -arch sm_11 -I/usr/local/lib/python2.6/dist-packages/pycuda-0.94.2-py2.6-linux-x86_64.egg/pycuda/../include/pycuda kernel.cu': nvcc fatal : Unknown option 'Wall'
来源问题是,我花了整整一天的调试,因为我忽略了从隐性转换float
到int
.