c - 我将如何使用 SSE 使稀疏浮点矩阵卷积更快?
问题描述
作为作业的一部分,我收到了这段 C 代码。我的任务是使用 OpenMP 和英特尔 SSE 使其运行得更快。我了解 SSE 和 OpenMP 背后的逻辑,但是我无法完全理解我的方法应该做什么。
我在下面给出了代码片段。任何帮助表示赞赏。
void team_conv_sparse(float *** image, struct sparse_matrix *** kernels,
float *** output, int width, int height,
int nchannels, int nkernels, int kernel_order) {
int h, w, x, y, c, m, index;
float value;
// initialize the output matrix to zero
for ( m = 0; m < nkernels; m++ ) {
for ( h = 0; h < height; h++ ) {
for ( w = 0; w < width; w++ ) {
output[m][h][w] = 0.0;
}
}
}
DEBUGGING(fprintf(stderr, "w=%d, h=%d, c=%d\n", w, h, c));
// now compute multichannel, multikernel convolution
// #pragma omp parallel for
for ( w = 0; w < width; w++ ) {
for ( h = 0; h < height; h++ ) {
for ( x = 0; x < kernel_order; x++) {
for ( y = 0; y < kernel_order; y++ ) {
struct sparse_matrix * kernel = kernels[x][y];
for ( m = 0; m < nkernels; m++ ) {
for ( index = kernel->kernel_starts[m]; index < kernel->kernel_starts[m+1]; index++ ) {
int this_c = kernel->channel_numbers[index];
assert( (this_c >= 0) && (this_c < nchannels) );
value = kernel->values[index];
output[m][h][w] += image[w+x][h+y][this_c] * value;
}
} // m
} // y
} // x
} // h
}// w
}
解决方案
推荐阅读
- python - 使用 python 下载电子邮件附件时出错
- javascript - 为什么我们不应该使用 ref?
- python - 布尔索引的差异取决于索引符号
- javascript - 如何处理异步请求并正确显示数据
- tmux - 发送密钥的 tmux 错误(尝试与 xclip 交互)
- google-apps-script - Apps Script Advanced Calendar API - 插入带有标题的新事件 - 错误“无效的源 URL:”
- javascript - PHP 按位异或与 JavaScript 按位异或
- reactjs - reactjs中如何导入
- html - 如何保持两个不同 HTML 元素之间的高度和宽度?
- javascript - Angular 6:Npm 错误!缺少脚本:部署到 heroku 时开始