我正在使用 Hexagon-SDK 3.0 为 HVX DSP 架构编译我的示例应用程序。有许多与 Hexagon-LLVM 相关的工具可供使用,位于以下文件夹:
~/Qualcomm/HEXAGON_Tools/7.2.12/Tools/bin
我写了一个小例子来计算两个数组的乘积,以确保我可以利用 HVX 硬件加速。但是,当我生成我的程序集时,无论是使用-S
,还是使用,-S -emit-llvm
我都没有找到任何 HVX 指令的定义,例如vmem
,vX
等。我的 C 应用程序现在正在执行,hexagon-sim
直到我设法找到一种在板也。
据我了解,我需要在 C Intrinsics 中定义我的 HVX 部分代码,但无法调整现有示例以满足我自己的需求。如果有人可以演示如何完成此过程,那就太好了。同样在Hexagon V62 程序员参考手册中,许多内在指令都没有定义。
这是我用纯 C 编写的小应用程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#if defined(__hexagon__)
#include "hexagon_standalone.h"
#include "subsys.h"
#endif
#include "io.h"
#include "hvx.cfg.h"
#define KERNEL_SIZE 9
#define Q 8
#define PRECISION (1<<Q)
double vectors_dot_prod2(const double *x, const double *y, int n)
{
double res = 0.0;
int i = 0;
for (; i <= n-4; i+=4)
{
res += (x[i] * y[i] +
x[i+1] * y[i+1] +
x[i+2] * y[i+2] +
x[i+3] * y[i+3]);
}
for (; i < n; i++)
{
res += x[i] * y[i];
}
return res;
}
int main (int argc, char* argv[])
{
int n;
long long start_time, total_cycles;
/* -----------------------------------------------------*/
/* Allocate memory for input/output */
/* -----------------------------------------------------*/
//double *res = memalign(VLEN, 4 *sizeof(double));
const double *x = memalign(VLEN, n *sizeof(double));
const double *y = memalign(VLEN, n *sizeof(double));
if ( *x == NULL || *y == NULL ){
printf("Error: Could not allocate Memory for image\n");
return 1;
}
#if defined(__hexagon__)
subsys_enable();
SIM_ACQUIRE_HVX;
#if LOG2VLEN == 7
SIM_SET_HVX_DOUBLE_MODE;
#endif
#endif
/* -----------------------------------------------------*/
/* Call fuction */
/* -----------------------------------------------------*/
RESET_PMU();
start_time = READ_PCYCLES();
vectors_dot_prod2(x,y,n);
total_cycles = READ_PCYCLES() - start_time;
DUMP_PMU();
printf("Array product of x[i] * y[i] = %f\n",vectors_dot_prod2(x,y,4));
#if defined(__hexagon__)
printf("AppReported (HVX%db-mode): Array product of x[i] * y[i] =%f\n", VLEN, vectors_dot_prod2(x,y,4));
#endif
return 0;
}
我使用以下方法编译它hexagon-clang
:
hexagon-clang -v -O2 -mv60 -mhvx-double -DLOG2VLEN=7 -I../../common/include -I../include -DQDSP6SS_PUB_BASE=0xFE200000 -o arrayProd.o -c arrayProd.c
然后将其与subsys.o
(在 DSK 中找到并已编译)链接并-lhexagon
生成我的可执行文件:
hexagon-clang -O2 -mv60 -o arrayProd.exe arrayProd.o subsys.o -lhexagon
最后,使用 sim 运行它:
hexagon-sim -mv60 arrayProd.exe