Poplar codelet 如何包含来自其他头文件的代码?
How can Poplar codelets include code from other header files?
小码是否可以引用其他文件(如头文件)中的代码?
如果我有小码文件
//FileA.cpp
#include "FileB.h"
class SomeCustomVertex : public Vertex {
public:
bool compute() {
int a = SomeConstantDefinedInFileB;
}
...
}
和其他一些“codelet”文件
//FileB.h
const int SomeConstantDefineInFileB = 42;
并且在主机图形程序中:
graph.addCodelets({"codelets/FileA.cpp", "codelets/FileB.h"});
我从 popc
得到一个编译错误:
fatal error: 'FileB.h' file not found
#include "FileB.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
terminate called after throwing an instance of 'poplar::graph_program_compilation_error'
what(): Codelet compilation failed (see compiler output for details)
我想通了。
Graph::addCodelets
有一个参数StringRef compileFlags = ""
,你可以用它来注入编译器选项。
popc --help
显示一个选项
-I arg Add directory to include search path
因此,当我在主机程序中使用 graph.addCodelets({"codelets/FileA.cpp"}, "-I codelets");
,并将我的小码放在 'codelets' 子目录中时,这有效。无需在参数中明确列出“.h”文件。
顺便说一句,这也是确保自定义小码的编译器优化 (-O3
) 的好方法。
小码是否可以引用其他文件(如头文件)中的代码?
如果我有小码文件
//FileA.cpp
#include "FileB.h"
class SomeCustomVertex : public Vertex {
public:
bool compute() {
int a = SomeConstantDefinedInFileB;
}
...
}
和其他一些“codelet”文件
//FileB.h
const int SomeConstantDefineInFileB = 42;
并且在主机图形程序中:
graph.addCodelets({"codelets/FileA.cpp", "codelets/FileB.h"});
我从 popc
得到一个编译错误:
fatal error: 'FileB.h' file not found
#include "FileB.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
terminate called after throwing an instance of 'poplar::graph_program_compilation_error'
what(): Codelet compilation failed (see compiler output for details)
我想通了。
Graph::addCodelets
有一个参数StringRef compileFlags = ""
,你可以用它来注入编译器选项。
popc --help
显示一个选项
-I arg Add directory to include search path
因此,当我在主机程序中使用 graph.addCodelets({"codelets/FileA.cpp"}, "-I codelets");
,并将我的小码放在 'codelets' 子目录中时,这有效。无需在参数中明确列出“.h”文件。
顺便说一句,这也是确保自定义小码的编译器优化 (-O3
) 的好方法。