我想编译一个ispc程序。我正试图为他们的一个示例程序生成可执行文件。
我有以下内容的simple.cpp
#include <stdio.h>
#include <stdlib.h>
// Include the header file that the ispc compiler generates
#include "simple_ispc.h"
using namespace ispc;
int main() {
float vin[16], vout[16];
// Initialize input buffer
for (int i = 0; i < 16; ++i)
vin[i] = (float)i;
// Call simple() function from simple.ispc file
simple(vin, vout, 16);
// Print results
for (int i = 0; i < 16; ++i)
printf("%d: simple(%f) = %f\n", i, vin[i], vout[i]);
return 0;
}我有以下内容的simple.ispc
export void simple(uniform float vin[], uniform float vout[],
uniform int count) {
foreach (index = 0 ... count) {
// Load the appropriate input value for this program instance.
float v = vin[index];
// Do an arbitrary little computation, but at least make the
// computation dependent on the value being processed
if (v < 3.)
v = v * v;
else
v = sqrt(v);
// And write the result to the output array.
vout[index] = v;
}
}我可以使用cmake https://github.com/ispc/ispc/tree/main/examples/cpu/simple来获取可执行文件,但是我想知道运行simple.cpp文件需要执行的原始命令。有人能告诉我如何用ispc编译和运行simple.cpp文件吗?
发布于 2021-04-13 18:59:18
根据ISPC用户指南,您只需在终端中使用ispc作为命令:
ispc simple.ispc -o simple.o这将生成一个对象文件simple.o,您可以使用常规的C++编译器(如g++ )链接到C++文件。
编辑
编译为simple_ispc.h
-h标志还可以用来指示ispc生成一个C/C++头文件,其中包括C/C++声明的C-可调用的ispc函数以及传递给它的类型。
所以你很可能会做一些事情
ispc simple.ispc -h simple_ispc.h然后
g++ simple.cpp -o executable得到可执行文件。
发布于 2021-04-20 03:57:06
首先,使用ispc编译器创建ispc头文件和对象文件。
ispc --target=avx2-i32x8 simple.ispc -h simple_ispc.h -o simple_ispc.o然后创建cpp的对象文件并将2个对象文件链接在一起。
g++ -c simple.cpp -o simple.o
g++ simple.o simple_ispc.o -o executable或在ispc头文件和obj文件创建后,在一个命令中执行可执行文件的创建。
g++ simple.cpp simple_ispc.o -o executable此外,如果您有clang/llvm,也可以使用它们进行编译。以下是步骤:https://ispc.github.io/faq.html#is-it-possible-to-inline-ispc-functions-in-c-c-code
// emit llvm IR
ispc --emit-llvm --target=avx2-i32x8 -h simple_ispc.h -o simple_ispc.bc simple.ispc
clang -O2 -c -emit-llvm -o simple.bc simple.cpp
// link the two IR files into a single file and run the LLVM optimizer on the result
llvm-link simple.bc simple_ispc.bc -o - | opt -O3 -o simple_opt.bc
// generate the native object file
llc -filetype=obj simple_opt.bc -o simple.o
// generate the executable
clang -o simple simple.ohttps://stackoverflow.com/questions/67080716
复制相似问题