有没有一个标准,跨入的memcpy的版本? [英] Is there a standard, strided version of memcpy?
问题描述
我有一个列向量这是10个元素长。我有一个矩阵B是10×10的内存存储B是列为主。我愿与列向量A到覆盖第一个行 B中。
I have a column vector A which is 10 elements long. I have a matrix B which is 10 by 10. The memory storage for B is column major. I would like to overwrite the first row in B with the column vector A.
很显然,我可以这样做:
Clearly, I can do:
for ( int i=0; i < 10; i++ )
{
B[0 + 10 * i] = A[i];
}
在这里我在离开为零0 + 10 * I
来突出B使用列存储的主要(零是行索引)。
where I've left the zero in 0 + 10 * i
to highlight that B uses column-major storage (zero is the row-index).
在今晚CUDA的一些土地有心计,我有一个想法,可能有一个CPU的功能来执行跨进的memcpy?我想在一个低的水平,业绩将取决于是否存在一个跨入加载/存储指令的,我不记得有x86汇编为?
After some shenanigans in CUDA-land tonight, I had a thought that there might be a CPU function to perform a strided memcpy?? I guess at a low-level, performance would depend on the existence of a strided load/store instruction, which I don't recall there being in x86 assembly?
推荐答案
简短的回答:你写的code是一样快,因为它会得到
Short answer: The code you have written is as fast as it's going to get.
龙的回答是:的memcpy
功能是通过一些复杂的内部函数或汇编语言编写,因为它在具有任意大小和对齐内存操作数进行操作。如果你是一个覆盖矩阵的列,那么你的操作数将具有自然对齐,并且您将不再需要求助于同样的招数来获得不俗的速度。
Long answer: The memcpy
function is written using some complicated intrinsics or assembly because it operates on memory operands that have arbitrary size and alignment. If you are overwriting a column of a matrix, then your operands will have natural alignment, and you won't need to resort to the same tricks to get decent speed.
这篇关于有没有一个标准,跨入的memcpy的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!