我需要帮助了解我的块和网格的大小。我正在构建一个Python应用程序,基于scipy进行度量计算,如欧几里得距离、曼哈顿距离、皮尔逊相关系数、余弦相似度等。
该项目是PycudaDistances。
它似乎在小数组中运行得非常好。当我执行更详尽的测试时,不幸的是它没有工作。我下载了movielens集(http://www.grouplens.org/node/73)。
使用
使用更大的数组算法不再起作用。我面临以下错误: pycuda._driver.LogicError: cuFuncSetBlockShape failed: invalid value.
研究这个错误,我发现需要使用块和网格来处理更大的块。
该项目是PycudaDistances。
它似乎在小数组中运行得非常好。当我执行更详尽的测试时,不幸的是它没有工作。我下载了movielens集(http://www.grouplens.org/node/73)。
使用
Movielens
100k,我声明了一个形状为(943,1682)的数组。也就是说,用户有943个,评估了1682部电影。未被分类器用户评估的电影我将其配置为0。使用更大的数组算法不再起作用。我面临以下错误: pycuda._driver.LogicError: cuFuncSetBlockShape failed: invalid value.
研究这个错误,我发现需要使用块和网格来处理更大的块。
我希望你能帮忙将欧几里得距离算法适应于从小到大的数组。
def euclidean_distances(X, Y=None, inverse=True):
X, Y = check_pairwise_arrays(X,Y)
rows = X.shape[0]
cols = Y.shape[0]
solution = numpy.zeros((rows, cols))
solution = solution.astype(numpy.float32)
kernel_code_template = """
#include <math.h>
__global__ void euclidean(float *x, float *y, float *solution) {
int idx = threadIdx.x + blockDim.x * blockIdx.x;
int idy = threadIdx.y + blockDim.y * blockIdx.y;
float result = 0.0;
for(int iter = 0; iter < %(NDIM)s; iter++) {
float x_e = x[%(NDIM)s * idy + iter];
float y_e = y[%(NDIM)s * idx + iter];
result += pow((x_e - y_e), 2);
}
int pos = idx + %(NCOLS)s * idy;
solution[pos] = sqrt(result);
}
"""
kernel_code = kernel_code_template % {
'NCOLS': cols,
'NDIM': X.shape[1]
}
mod = SourceModule(kernel_code)
func = mod.get_function("euclidean")
func(drv.In(X), drv.In(Y), drv.Out(solution), block=(cols, rows, 1))
return numpy.divide(1.0, (1.0 + solution)) if inverse else solution
更多详情请参见:https://github.com/vinigracindo/pycudaDistances/blob/master/distances.py