Skip to content

Commit d1bc634

Browse files
committed
Add tests for creating program with IL
For testing boost::compute::program::create_with_il() 32- and 64-bit SPIR-V binaries were added to test/data dir. File test/data/program.cl contains OpenCL C source code of those binaries.
1 parent 7542dd0 commit d1bc634

File tree

5 files changed

+94
-0
lines changed

5 files changed

+94
-0
lines changed

test/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ if(${BOOST_COMPUTE_ENABLE_COVERAGE} AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU
5050
add_definitions(-fprofile-arcs -ftest-coverage)
5151
endif()
5252

53+
# add path to test data dir
54+
add_definitions(-DBOOST_COMPUTE_TEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/data")
55+
5356
function(add_compute_test TEST_NAME TEST_SOURCE)
5457
get_filename_component(TEST_TARGET ${TEST_SOURCE} NAME_WE)
5558
add_executable(${TEST_TARGET} ${TEST_SOURCE})

test/data/program.cl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//---------------------------------------------------------------------------//
2+
// Copyright (c) 2017 Jakub Szuppe <j.szuppe@gmail.com>
3+
//
4+
// Distributed under the Boost Software License, Version 1.0
5+
// See accompanying file LICENSE_1_0.txt or copy at
6+
// http://www.boost.org/LICENSE_1_0.txt
7+
//
8+
// See http://boostorg.github.com/compute for more information.
9+
//---------------------------------------------------------------------------//
10+
11+
__kernel void foobar(__global int* x)
12+
{
13+
const int gid = get_global_id(0);
14+
x[gid] = gid;
15+
}

test/data/program.spirv32

472 Bytes
Binary file not shown.

test/data/program.spirv64

528 Bytes
Binary file not shown.

test/test_program.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,82 @@ BOOST_AUTO_TEST_CASE(create_with_binary)
126126
BOOST_CHECK_EQUAL(binary_bar_kernel.name(), std::string("bar"));
127127
}
128128

129+
#ifdef BOOST_COMPUTE_CL_VERSION_2_1
130+
BOOST_AUTO_TEST_CASE(create_with_il)
131+
{
132+
size_t device_address_space_size = device.address_bits();
133+
std::string file_path(BOOST_COMPUTE_TEST_DATA_PATH);
134+
if(device_address_space_size == 64)
135+
{
136+
file_path += "/program.spirv64";
137+
}
138+
else
139+
{
140+
file_path += "/program.spirv32";
141+
}
142+
143+
// create program from il
144+
boost::compute::program il_program;
145+
BOOST_CHECK_NO_THROW(
146+
il_program = boost::compute::program::create_with_il_file(
147+
file_path, context
148+
)
149+
);
150+
BOOST_CHECK_NO_THROW(il_program.build());
151+
152+
// create kernel (to check if program was loaded correctly)
153+
BOOST_CHECK_NO_THROW(il_program.create_kernel("foobar"));
154+
}
155+
156+
BOOST_AUTO_TEST_CASE(get_program_il_binary)
157+
{
158+
size_t device_address_space_size = device.address_bits();
159+
std::string file_path(BOOST_COMPUTE_TEST_DATA_PATH);
160+
if(device_address_space_size == 64)
161+
{
162+
file_path += "/program.spirv64";
163+
}
164+
else
165+
{
166+
file_path += "/program.spirv32";
167+
}
168+
169+
// create program from il
170+
boost::compute::program il_program;
171+
BOOST_CHECK_NO_THROW(
172+
il_program = boost::compute::program::create_with_il_file(
173+
file_path, context
174+
)
175+
);
176+
BOOST_CHECK_NO_THROW(il_program.build());
177+
178+
std::vector<unsigned char> il_binary;
179+
BOOST_CHECK_NO_THROW(il_binary = il_program.il_binary());
180+
181+
// create program from loaded il binary
182+
BOOST_CHECK_NO_THROW(
183+
il_program = boost::compute::program::create_with_il(il_binary, context)
184+
);
185+
BOOST_CHECK_NO_THROW(il_program.build());
186+
187+
// create kernel (to check if program was loaded correctly)
188+
BOOST_CHECK_NO_THROW(il_program.create_kernel("foobar"));
189+
}
190+
191+
BOOST_AUTO_TEST_CASE(get_program_il_binary_empty)
192+
{
193+
boost::compute::program program;
194+
BOOST_CHECK_NO_THROW(
195+
program = boost::compute::program::create_with_source(source, context)
196+
);
197+
BOOST_CHECK_NO_THROW(program.build());
198+
199+
std::vector<unsigned char> il_binary;
200+
il_binary = program.il_binary();
201+
BOOST_CHECK(il_binary.empty());
202+
}
203+
#endif // BOOST_COMPUTE_CL_VERSION_2_1
204+
129205
BOOST_AUTO_TEST_CASE(create_with_source_doctest)
130206
{
131207
//! [create_with_source]

0 commit comments

Comments
 (0)