From 7bb0da6cf4937aaa5300c7181634517902244f19 Mon Sep 17 00:00:00 2001 From: Luo Xionghu Date: Wed, 4 Nov 2015 13:45:46 +0800 Subject: utest: add utest to generate spir binary from beignet. include case compile_spir_binary and build_spir_binary. Signed-off-by: Luo Xionghu Reviewed-by: Yang Rong --- utests/get_cl_info.cpp | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) (limited to 'utests/get_cl_info.cpp') diff --git a/utests/get_cl_info.cpp b/utests/get_cl_info.cpp index 3109c8e4..25366902 100644 --- a/utests/get_cl_info.cpp +++ b/utests/get_cl_info.cpp @@ -418,6 +418,105 @@ void get_build_llvm_info(void) MAKE_UTEST_FROM_FUNCTION(get_build_llvm_info); +// This method uses clGetProgramBuildInfo to check the dump-spir-binary options +// and verifies that the spir dump file is actually generated in the backend. +void compile_spir_binary(void) +{ + map maps; + cl_build_status expect_status; + char spir_file[] = "test_spir_dump.txt"; + char compile_opt[] = "-dump-spir-binary=test_spir_dump.txt"; + FILE *fp = NULL; + int sz; + + //Remove any pre-existing file + if( (fp = fopen(spir_file, "r")) != NULL) { + fclose(fp); + std::remove(spir_file); + } + + OCL_CALL (cl_kernel_compile, "compiler_ceil.cl", "compiler_ceil", compile_opt); + + /* Do our test.*/ + expect_status = CL_BUILD_SUCCESS; + maps.insert(make_pair(CL_PROGRAM_BUILD_STATUS, + (void *)(new Info_Result(expect_status)))); + sz = strlen(compile_opt) + 1; + maps.insert(make_pair(CL_PROGRAM_BUILD_OPTIONS, + (void *)(new Info_Result(compile_opt, sz)))); + + for (map::iterator x = maps.begin(); x != maps.end(); ++x) { + switch (x->first) { + case CL_PROGRAM_BUILD_STATUS: + CALL_PROG_BUILD_INFO_AND_RET(cl_build_status); + break; + case CL_PROGRAM_BUILD_OPTIONS: + CALL_PROG_BUILD_INFO_AND_RET(char *); + break; + default: + break; + } + } + + //Test is successful if the backend created the file + if( (fp = fopen(spir_file, "r")) == NULL) { + std::cout << "SPIR file creation.. FAILED"; + OCL_ASSERT(0); + } else { + fclose(fp); + std::cout << "SPIR file created.. SUCCESS"; + } +} +MAKE_UTEST_FROM_FUNCTION(compile_spir_binary); + +void build_spir_binary(void) +{ + map maps; + cl_build_status expect_status; + char spir_file[] = "test_spir_dump.txt"; + char build_opt[] = "-dump-spir-binary=test_spir_dump.txt"; + FILE *fp = NULL; + int sz; + + //Remove any pre-existing file + if( (fp = fopen(spir_file, "r")) != NULL) { + fclose(fp); + std::remove(spir_file); + } + + OCL_CALL (cl_kernel_init, "compiler_ceil.cl", "compiler_ceil", SOURCE, build_opt); + + /* Do our test.*/ + expect_status = CL_BUILD_SUCCESS; + maps.insert(make_pair(CL_PROGRAM_BUILD_STATUS, + (void *)(new Info_Result(expect_status)))); + sz = strlen(build_opt) + 1; + maps.insert(make_pair(CL_PROGRAM_BUILD_OPTIONS, + (void *)(new Info_Result(build_opt, sz)))); + + for (map::iterator x = maps.begin(); x != maps.end(); ++x) { + switch (x->first) { + case CL_PROGRAM_BUILD_STATUS: + CALL_PROG_BUILD_INFO_AND_RET(cl_build_status); + break; + case CL_PROGRAM_BUILD_OPTIONS: + CALL_PROG_BUILD_INFO_AND_RET(char *); + break; + default: + break; + } + } + + //Test is successful if the backend created the file + if( (fp = fopen(spir_file, "r")) == NULL) { + std::cout << "SPIR file creation.. FAILED"; + OCL_ASSERT(0); + } else { + fclose(fp); + std::cout << "SPIR file created.. SUCCESS"; + } +} +MAKE_UTEST_FROM_FUNCTION(build_spir_binary); // This method uses clGetProgramBuildInfo to check the asm dump build options sent // And verifies that the asm dump file is actually generated in the backend. void get_build_asm_info(void) -- cgit v1.2.1