From d1bc634fc5ae1feb9a255f275e28ff623cc090da Mon Sep 17 00:00:00 2001 From: Jakub Szuppe Date: Mon, 22 May 2017 22:16:45 +0200 Subject: [PATCH] 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. --- test/CMakeLists.txt | 3 ++ test/data/program.cl | 15 ++++++++ test/data/program.spirv32 | Bin 0 -> 472 bytes test/data/program.spirv64 | Bin 0 -> 528 bytes test/test_program.cpp | 76 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 94 insertions(+) create mode 100644 test/data/program.cl create mode 100644 test/data/program.spirv32 create mode 100644 test/data/program.spirv64 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 42e3969e..a0ca0cf1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -50,6 +50,9 @@ if(${BOOST_COMPUTE_ENABLE_COVERAGE} AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU add_definitions(-fprofile-arcs -ftest-coverage) endif() +# add path to test data dir +add_definitions(-DBOOST_COMPUTE_TEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/data") + function(add_compute_test TEST_NAME TEST_SOURCE) get_filename_component(TEST_TARGET ${TEST_SOURCE} NAME_WE) add_executable(${TEST_TARGET} ${TEST_SOURCE}) diff --git a/test/data/program.cl b/test/data/program.cl new file mode 100644 index 00000000..c8962b88 --- /dev/null +++ b/test/data/program.cl @@ -0,0 +1,15 @@ +//---------------------------------------------------------------------------// +// Copyright (c) 2017 Jakub Szuppe +// +// Distributed under the Boost Software License, Version 1.0 +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// +// See http://boostorg.github.com/compute for more information. +//---------------------------------------------------------------------------// + +__kernel void foobar(__global int* x) +{ + const int gid = get_global_id(0); + x[gid] = gid; +} diff --git a/test/data/program.spirv32 b/test/data/program.spirv32 new file mode 100644 index 0000000000000000000000000000000000000000..79eb61539ffcad59a591d0a82bc5491043d2c92a GIT binary patch literal 472 zcmZQ(Qf6mhU}Ruq;A7xtfB-=TCI%J;1_lt#3Z>Z?7#O%2SQ!`@7#REuQuCaB^omPT z7#R2%n89L93=9nX46Fs4U*8 zG&85fGtWIIKPfTCGp{T^Ik6-&KhHCTfq{XQfti7efq|idfq}uDfrSC&4sHep1{pA) z8O#?0vw6X6O$Or31-W08frSC&UImDE8N?Y_7?>Ftz+xa;fq@0=e~>hYFU-IM_7_N; z9qcxUT15sH1`Y-WupCI-8mbTER*+sZr0@XoL2Atzm>EE7L4Nzez{CLZlP%PK9;n%Y x46IwkfW$z0-56NG`uG?az~KUtvtwXo0P#U=kbgjN_LqT?!GeL20RSVsDhdDq literal 0 HcmV?d00001 diff --git a/test/data/program.spirv64 b/test/data/program.spirv64 new file mode 100644 index 0000000000000000000000000000000000000000..57113d41af1071b57ffc8b1f29433800e5e4689c GIT binary patch literal 528 zcmZQ(Qf6mhU}Ruq;A0SCfB-=TCI%J;1_lt#3Z>bgG&chS12+RJ10w?igMUG4p0kf$ zaY+gT10Mr30}}%S81pl*GJw=`F)%Qs<>x0Q7BMg|gCPS$K_4RnE7$}EhWPm6g3O|_ zc&F0LoD$DG_niEs#2nAOvi#)4lFa-(&lCm*237`U29TW<3=9nJ3@i*F_kj2^U_LXL zF9v4wg4vo3#F-0nzbFF>*u4%AZ!>`S>`#z52iUC)3?TiA3@i+s3=Cj7khnEeAIR+>y=F+^1LA|!nlmsnfYgHg_Je_mfro*C z!4_&iFVyTn23D|p`4|`&Kw==hg$yiUJNX$valpV(1oe{u0|Ns{%#DE+Y_1?U-WV7_ a;&u$I3?M#89u#Mwxc il_binary; + BOOST_CHECK_NO_THROW(il_binary = il_program.il_binary()); + + // create program from loaded il binary + BOOST_CHECK_NO_THROW( + il_program = boost::compute::program::create_with_il(il_binary, context) + ); + BOOST_CHECK_NO_THROW(il_program.build()); + + // create kernel (to check if program was loaded correctly) + BOOST_CHECK_NO_THROW(il_program.create_kernel("foobar")); +} + +BOOST_AUTO_TEST_CASE(get_program_il_binary_empty) +{ + boost::compute::program program; + BOOST_CHECK_NO_THROW( + program = boost::compute::program::create_with_source(source, context) + ); + BOOST_CHECK_NO_THROW(program.build()); + + std::vector il_binary; + il_binary = program.il_binary(); + BOOST_CHECK(il_binary.empty()); +} +#endif // BOOST_COMPUTE_CL_VERSION_2_1 + BOOST_AUTO_TEST_CASE(create_with_source_doctest) { //! [create_with_source]