mirror of
https://github.com/boostorg/compute.git
synced 2026-02-22 03:12:19 +00:00
added headers to program::compile
This commit is contained in:
@@ -192,6 +192,58 @@ BOOST_AUTO_TEST_CASE(compile_and_link)
|
||||
linked_program.create_kernel("square_kernel");
|
||||
BOOST_CHECK_EQUAL(square_kernel.name(), "square_kernel");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compile_and_link_with_headers)
|
||||
{
|
||||
REQUIRES_OPENCL_VERSION(1,2);
|
||||
|
||||
if(!supports_compile_program(device) || !supports_link_program(device)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// create the header programs
|
||||
const char square_header_source[] = BOOST_COMPUTE_STRINGIZE_SOURCE(
|
||||
T square(T x) { return x * x; }
|
||||
);
|
||||
const char div2_header_source[] = BOOST_COMPUTE_STRINGIZE_SOURCE(
|
||||
T div2(T x) { return x / 2; }
|
||||
);
|
||||
|
||||
compute::program square_header_program =
|
||||
compute::program::create_with_source(square_header_source, context);
|
||||
compute::program div2_header_program =
|
||||
compute::program::create_with_source(div2_header_source, context);
|
||||
|
||||
// create the kernel program
|
||||
const char kernel_source[] =
|
||||
"#include \"square.h\"\n"
|
||||
"#include \"div2.h\"\n"
|
||||
"__kernel void squareby2_kernel(__global int *x)"
|
||||
"{"
|
||||
" x[0] = div2(square(x[0]));"
|
||||
"}";
|
||||
|
||||
compute::program square_program =
|
||||
compute::program::create_with_source(kernel_source, context);
|
||||
|
||||
std::vector<std::pair<std::string, compute::program> > header_programs;
|
||||
header_programs.push_back(std::make_pair("square.h", square_header_program));
|
||||
header_programs.push_back(std::make_pair("div2.h", div2_header_program));
|
||||
|
||||
square_program.compile("-DT=int", header_programs);
|
||||
|
||||
// link program
|
||||
std::vector<compute::program> programs;
|
||||
programs.push_back(square_program);
|
||||
|
||||
compute::program linked_program =
|
||||
compute::program::link(programs, context);
|
||||
|
||||
// create the square kernel
|
||||
compute::kernel square_kernel =
|
||||
linked_program.create_kernel("squareby2_kernel");
|
||||
BOOST_CHECK_EQUAL(square_kernel.name(), "squareby2_kernel");
|
||||
}
|
||||
#endif // CL_VERSION_1_2
|
||||
|
||||
BOOST_AUTO_TEST_CASE(build_log)
|
||||
|
||||
Reference in New Issue
Block a user