gpt4 book ai didi

c - 在 XeonPhi 上使用 AVX 内联汇编的 vector 和

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:22:44 24 4
gpt4 key购买 nike

我刚开始使用英特尔至强融核协处理器。我想使用 AVX 512 位指令为简单的 vector 和编写代码。我使用 k1om-mpss-linux-gcc 作为编译器并想编写内联汇编。这是我的代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <assert.h>
#include <stdint.h>

void* aligned_malloc(size_t size, size_t alignment) {

uintptr_t r = (uintptr_t)malloc(size + --alignment + sizeof(uintptr_t));
uintptr_t t = r + sizeof(uintptr_t);
uintptr_t o =(t + alignment) & ~(uintptr_t)alignment;
if (!r) return NULL;
((uintptr_t*)o)[-1] = r;
return (void*)o;
}

int main(int argc, char* argv[])
{
printf("Starting calculation...\n");
int i;
const int length = 65536;

unsigned *A = (unsigned*) aligned_malloc(length * sizeof(unsigned), 64);
unsigned *B = (unsigned*) aligned_malloc(length * sizeof(unsigned), 64);
unsigned *C = (unsigned*) aligned_malloc(length * sizeof(unsigned), 64);

for(i=0; i<length; i++){
A[i] = 1;
B[i] = 2;
}

const int AVXLength = length / 16;
unsigned char * pA = (unsigned char *) A;
unsigned char * pB = (unsigned char *) B;
unsigned char * pC = (unsigned char *) C;
for(i=0; i<AVXLength; i++ ){
__asm__("vmovdqa32 %1,%%zmm0\n"
"vmovdqa32 %2,%%zmm1\n"
"vpaddd %0,%%zmm0,%%zmm1;"
: "=m" (pC) : "m" (pA), "m" (pB));

pA += 64;
pB += 64;
pC += 64;
}

// To prove that the program actually worked
for (i=0; i <5 ; i++)
{
printf("C[%d] = %f\n", i, C[i]);
}

}

但是,当我运行该程序时,出现了 asm 部分的段错误。有人可以帮我吗???

谢谢

最佳答案

Xeon Phi Knights Corner 不支持 AVX。它仅支持一组特殊的 vector 扩展,称为 Intel Initial Many Core Instructions (Intel IMCI), vector 大小为 512b。因此,尝试将任何类型的 AVX 特定程序集放入 KNC 代码中都会导致崩溃。

只需等待骑士登陆。它将支持 AVX-512 vector 扩展。

关于c - 在 XeonPhi 上使用 AVX 内联汇编的 vector 和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34114092/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com