[Beignet] [PATCH v2 2/2] add utest for load spir binary.
xionghu.luo at intel.com
xionghu.luo at intel.com
Fri Feb 27 23:53:28 PST 2015
From: Luo Xionghu <xionghu.luo at intel.com>
To generate SPIR binary, please refer to the page
https://github.com/KhronosGroup/SPIR.
For llvm3.2, the command is "clang -cc1 -emit-llvm-bc -triple
spir-unknown-unknown -cl-std=CL1.2 -include opencl_spir.h
compiler_ceil.cl -o compiler_ceil32.spir"
For llvm3.5, the option -cl-kernel-arg-info is required,
and option -fno-builtin is required to avoid warning.
v2: add missing load_program_from_spir.cpp file.
Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
---
kernels/compiler_ceil32.spir | Bin 0 -> 1732 bytes
utests/CMakeLists.txt | 1 +
utests/load_program_from_spir.cpp | 90 ++++++++++++++++++++++++++++++++++++++
3 files changed, 91 insertions(+)
create mode 100644 kernels/compiler_ceil32.spir
create mode 100644 utests/load_program_from_spir.cpp
diff --git a/kernels/compiler_ceil32.spir b/kernels/compiler_ceil32.spir
new file mode 100644
index 0000000000000000000000000000000000000000..ee6483476568e76f3765622cf8fd8a84a81e5d2a
GIT binary patch
literal 1732
zcmY*Ze at qis9Dmo=dzF at VhjdcL^}GWl{DJdCN2oy7a_Dd|OF{o|Kav$Q4cW$a6f6{z
z?Mkc199ya(3rm)zm*_$kvoJ#zvY6NcGX#k?E-{W6(*~$N=Aa6iZP~Byq0{V=d*65O
zec$Ik?|na?*C;1$igtv)r4X|93&?~J+5j&Om!0%ZTlUawwfhtmwQpW$E#@ts98}p|
zrp8mY#wc6usI at xx<W)D7H|NE~vZ+?pUMvR6 at wBzz;7EMLb1?^ysKtrU5X6!}0d0)W
zd90?<_oPoV|G<MirPp;X+s4l!enIChimt5A%_X?B?wSa5sLP6j!&(4YdwR7R35Tp&
zuu`j0wVr0&6W0PUt)>zOo3$XC6}jte{0t at B$hhVN*Nr5X)$?a5el89;e2S7Z#jk}b
zv8rf2?dBdU?in@!d)p&HEAI2)1UC^jeyt{5H}!mA0-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(D>)-6;06Hm;0+<D^6o3`)LAuXtA-Ecv{?WEv76zTM6N=y^``?m}n7F}}`57%A7
z at 3`rAT=VBA)QwG|qp>ZzLUKN`B$0b*`sv}UNSo2_%6kd&C`I0nkp)QbF#AkUZlh*J
zP_yk;m7B_NhaFVIfLt4$9Bfo^s26t)ciJD{5#a6Z_C|gp>AI|QhoyCEX_1mybHlXU
zFlcU=?H%k^@KGpRv!(!D#cUKnz<}K;Ae0BOLj8053+#030d at 7t!w&YR52{{8RWDVS
z(<v)i5o`s2nZi|&hS~&#To4N_-YOQNA+G&p2$j)OESKyx75Jpx_5rcE|Gp*S9JEHM
zgd*4==W`XcSp3t<Ye`{Of3ZEX<L5>ZU25Ir@$T3cEtXA91*$lCsKf+=CTiPbzrR6?
PvG47>gf#&JhVlFhihNjp
literal 0
HcmV?d00001
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index eaba27d..06baa68 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -192,6 +192,7 @@ set (utests_sources
compiler_time_stamp.cpp
compiler_double_precision.cpp
load_program_from_gen_bin.cpp
+ load_program_from_spir.cpp
get_arg_info.cpp
profiling_exec.cpp
enqueue_copy_buf.cpp
diff --git a/utests/load_program_from_spir.cpp b/utests/load_program_from_spir.cpp
new file mode 100644
index 0000000..3e4534c
--- /dev/null
+++ b/utests/load_program_from_spir.cpp
@@ -0,0 +1,90 @@
+#include "utest_helper.hpp"
+#include "utest_file_map.hpp"
+#include <cstring>
+#include <cmath>
+#include <algorithm>
+
+using namespace std;
+
+static void cpu(int global_id, float *src, float *dst) {
+ dst[global_id] = ceilf(src[global_id]);
+}
+
+static void test_load_program_from_spir(void)
+{
+ size_t param_value_size;
+ std::string extensionStr;
+ OCL_CALL (clGetPlatformInfo, platform, CL_PLATFORM_EXTENSIONS, 0, 0, ¶m_value_size);
+ std::vector<char> param_value(param_value_size);
+ OCL_CALL (clGetDeviceInfo, device, CL_DEVICE_EXTENSIONS, param_value_size, param_value.empty() ? NULL : ¶m_value.front(), ¶m_value_size);
+ if (!param_value.empty())
+ extensionStr = std::string(¶m_value.front(), param_value_size-1);
+
+ if (!std::strstr(extensionStr.c_str(), "cl_khr_spir")) {
+ OCL_ASSERT(0);
+ }
+
+ const size_t n = 16;
+ float cpu_dst[16], cpu_src[16];
+ cl_int status;
+ cl_int binary_status;
+ char *ker_path = NULL;
+
+ cl_file_map_t *fm = cl_file_map_new();
+ ker_path = cl_do_kiss_path("compiler_ceil32.spir", device);
+ OCL_ASSERT (cl_file_map_open(fm, ker_path) == CL_FILE_MAP_SUCCESS);
+
+ const unsigned char *src = (const unsigned char *)cl_file_map_begin(fm);
+ const size_t sz = cl_file_map_size(fm);
+
+ program = clCreateProgramWithBinary(ctx, 1,
+ &device, &sz, &src, &binary_status, &status);
+
+ OCL_ASSERT(program && status == CL_SUCCESS);
+
+ /* OCL requires to build the program even if it is created from a binary */
+ OCL_ASSERT(clBuildProgram(program, 1, &device, "-x spir", NULL, NULL) == CL_SUCCESS);
+
+ kernel = clCreateKernel(program, "compiler_ceil", &status);
+ OCL_ASSERT(status == CL_SUCCESS);
+
+ OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(float), NULL);
+ OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(float), NULL);
+ OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+ OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
+ globals[0] = 16;
+ locals[0] = 16;
+
+ // Run random tests
+ for (uint32_t pass = 0; pass < 8; ++pass) {
+ OCL_MAP_BUFFER(0);
+ for (int32_t i = 0; i < (int32_t) n; ++i)
+ cpu_src[i] = ((float*)buf_data[0])[i] = .1f * (rand() & 15) - .75f;
+ OCL_UNMAP_BUFFER(0);
+
+ // Run the kernel on GPU
+ OCL_NDRANGE(1);
+
+ // Run on CPU
+ for (int32_t i = 0; i < (int32_t) n; ++i) cpu(i, cpu_src, cpu_dst);
+
+ // Compare
+ OCL_MAP_BUFFER(1);
+
+#if 0
+ printf("#### GPU:\n");
+ for (int32_t i = 0; i < (int32_t) n; ++i)
+ printf(" %f", ((float *)buf_data[1])[i]);
+ printf("\n#### CPU:\n");
+ for (int32_t i = 0; i < (int32_t) n; ++i)
+ printf(" %f", cpu_dst[i]);
+ printf("\n");
+#endif
+
+ for (int32_t i = 0; i < (int32_t) n; ++i)
+ OCL_ASSERT(((float *)buf_data[1])[i] == cpu_dst[i]);
+ OCL_UNMAP_BUFFER(1);
+ }
+}
+
+MAKE_UTEST_FROM_FUNCTION(test_load_program_from_spir);
--
1.9.1
More information about the Beignet
mailing list