[Beignet] [PATCH] utests: Added unit tests to test LLVM and ASM dump generation in a two step build process with clCompile and clLink APIs.

Yang, Rong R rong.r.yang at intel.com
Tue Oct 13 00:15:28 PDT 2015


Pushed.

> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> Song, Ruiling
> Sent: Tuesday, October 13, 2015 10:24
> To: Navare, Manasi D; beignet at lists.freedesktop.org
> Subject: Re: [Beignet] [PATCH] utests: Added unit tests to test LLVM and
> ASM dump generation in a two step build process with clCompile and clLink
> APIs.
> 
> LGTM
> 
> Thanks!
> Ruiling
> 
> > -----Original Message-----
> > From: Navare, Manasi D
> > Sent: Monday, October 12, 2015 7:53 PM
> > To: beignet at lists.freedesktop.org; Song, Ruiling
> > Cc: Navare, Manasi D
> > Subject: [PATCH] utests: Added unit tests to test LLVM and ASM dump
> > generation in a two step build process with clCompile and clLink APIs.
> >
> >     This patch adds two new tests to the unit tests. It uses the existing
> >     framework and data structures and tests the llvm/asm dump generation
> >     when these flags (-dump-opt-llvm, -dump-opt-asm) are passed as
> > compile and link
> >     options to clCompileProgram and clLinkProgram APIs along with the
> > dump file names.
> >
> >     Method added:
> >     1) get_compile_llvm_info() tests LLVM dump generation after
> > clCompileProgram() stage
> >     2) get_link_asm_info() tests Gen ASM dump generation after
> > clLinkProgram() stage
> >
> > Signed-off-by: Manasi Navare <manasi.d.navare at intel.com>
> > ---
> >  utests/get_cl_info.cpp  |  95
> > +++++++++++++++++++++++++++++++++++++++++
> >  utests/utest_helper.cpp | 109
> > ++++++++++++++++++++++++++++++++++++++++++++++++
> >  utests/utest_helper.hpp |   4 ++
> >  3 files changed, 208 insertions(+)
> >
> > diff --git a/utests/get_cl_info.cpp b/utests/get_cl_info.cpp index
> > 7c03d95..48222a1 100644
> > --- a/utests/get_cl_info.cpp
> > +++ b/utests/get_cl_info.cpp
> > @@ -470,6 +470,101 @@ void get_build_asm_info(void)
> >
> >  MAKE_UTEST_FROM_FUNCTION(get_build_asm_info);
> >
> > +void get_compile_llvm_info(void)
> > +{
> > +    map<cl_program_info, void *> maps;
> > +    cl_build_status expect_status;
> > +    char llvm_file[] = "test_llvm_dump.txt";
> > +    char compile_opt[] = "-dump-opt-llvm=test_llvm_dump.txt";
> > +    FILE *fp = NULL;
> > +
> > +    //Remove any pre-existing file
> > +    if( (fp = fopen(llvm_file, "r")) != NULL) {
> > +        fclose(fp);
> > +        std::remove(llvm_file);
> > +    }
> > +
> > +    OCL_CALL (cl_kernel_compile, "compiler_if_else.cl",
> > + "compiler_if_else",
> > compile_opt);
> > +
> > +    /* Do our test.*/
> > +    expect_status = CL_BUILD_SUCCESS;
> > +    maps.insert(make_pair(CL_PROGRAM_BUILD_STATUS,
> > +                          (void *)(new
> > + Info_Result<cl_build_status>(expect_status))));
> > +
> > +
> > +    for (map<cl_program_info, void *>::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(llvm_file, "r")) == NULL) {
> > +        std::cout << "LLVM file creation.. FAILED";
> > +        OCL_ASSERT(0);
> > +    } else {
> > +        fclose(fp);
> > +        std::cout << "LLVM file created.. SUCCESS";
> > +    }
> > +
> > +}
> > +
> > +MAKE_UTEST_FROM_FUNCTION(get_compile_llvm_info);
> > +
> > +void get_link_asm_info(void)
> > +{
> > +    map<cl_program_info, void *> maps;
> > +    cl_build_status expect_status;
> > +    char asm_file[] = "test_asm_dump.txt";
> > +    char link_opt[] = "-dump-opt-asm=test_asm_dump.txt";
> > +    FILE *fp = NULL;
> > +
> > +    //Remove any pre-existing file
> > +    if( (fp = fopen(asm_file, "r")) != NULL) {
> > +        fclose(fp);
> > +        std::remove(asm_file);
> > +    }
> > +
> > +    OCL_CALL (cl_kernel_link, "compiler_if_else.cl",
> > + "compiler_if_else", link_opt);
> > +
> > +    /* Do our test.*/
> > +    expect_status = CL_BUILD_SUCCESS;
> > +    maps.insert(make_pair(CL_PROGRAM_BUILD_STATUS,
> > +                          (void *)(new
> > + Info_Result<cl_build_status>(expect_status))));
> > +
> > +
> > +    for (map<cl_program_info, void *>::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(asm_file, "r")) == NULL) {
> > +        std::cout << "ASM file creation.. FAILED";
> > +        OCL_ASSERT(0);
> > +    } else {
> > +        fclose(fp);
> > +        std::cout << "ASM file created.. SUCCESS";
> > +    }
> > +}
> > +
> > +MAKE_UTEST_FROM_FUNCTION(get_link_asm_info);
> > +
> >
> >  /* ***************************************************** *
> >   * clGetContextInfo                                      *
> > diff --git a/utests/utest_helper.cpp b/utests/utest_helper.cpp index
> > 8f772fd..aa2fc83 100644
> > --- a/utests/utest_helper.cpp
> > +++ b/utests/utest_helper.cpp
> > @@ -286,6 +286,115 @@ error:
> >    goto exit;
> >  }
> >
> > +int
> > +cl_kernel_compile(const char *file_name, const char *kernel_name,
> > +const char
> > * compile_opt)
> > +{
> > +  cl_file_map_t *fm = NULL;
> > +  char *ker_path = NULL;
> > +  cl_int status = CL_SUCCESS;
> > +  static const char *prevFileName = NULL;
> > +  cl_int err;
> > +
> > +  /* Load the program and build it */  if (!program || (program &&
> > + (!prevFileName || strcmp(prevFileName,
> > file_name)))) {
> > +    if (program) clReleaseProgram(program);
> > +    ker_path = cl_do_kiss_path(file_name, device);
> > +    cl_file_map_t *fm = cl_file_map_new();
> > +    FATAL_IF (cl_file_map_open(fm, ker_path) != CL_FILE_MAP_SUCCESS,
> > +                "Failed to open file \"%s\" with kernel \"%s\". Did
> > + you properly set
> > OCL_KERNEL_PATH variable?",
> > +                file_name, kernel_name);
> > +    const char *src = cl_file_map_begin(fm);
> > +    const size_t sz = cl_file_map_size(fm);
> > +    program = clCreateProgramWithSource(ctx, 1, &src, &sz, &status);
> > +    cl_file_map_delete(fm);
> > +
> > +    if (status != CL_SUCCESS) {
> > +      fprintf(stderr, "error calling clCreateProgramWithSource\n");
> > +      goto error;
> > +    }
> > +    prevFileName = file_name;
> > +
> > +    OCL_CALL (clCompileProgram, program,
> > +                                1, &device, // num_devices & device_list
> > +                                compile_opt, // compile_options
> > +                                0, // num_input_headers
> > +                                NULL,
> > +                                NULL,
> > +                                NULL, NULL);
> > +   OCL_ASSERT(err==CL_SUCCESS);
> > +
> > +  }
> > +
> > +exit:
> > +  free(ker_path);
> > +  cl_file_map_delete(fm);
> > +  return status;
> > +error:
> > +  prevFileName = NULL;
> > +  goto exit;
> > +}
> > +
> > +int
> > +cl_kernel_link(const char *file_name, const char *kernel_name, const
> > +char *
> > link_opt)
> > +{
> > +  cl_file_map_t *fm = NULL;
> > +  char *ker_path = NULL;
> > +  cl_int status = CL_SUCCESS;
> > +  static const char *prevFileName = NULL;
> > +  cl_int err;
> > +
> > +  /* Load the program and build it */  if (!program || (program &&
> > + (!prevFileName || strcmp(prevFileName,
> > file_name)))) {
> > +    if (program) clReleaseProgram(program);
> > +    ker_path = cl_do_kiss_path(file_name, device);
> > +    cl_file_map_t *fm = cl_file_map_new();
> > +    FATAL_IF (cl_file_map_open(fm, ker_path) != CL_FILE_MAP_SUCCESS,
> > +                "Failed to open file \"%s\" with kernel \"%s\". Did
> > + you properly set
> > OCL_KERNEL_PATH variable?",
> > +                file_name, kernel_name);
> > +    const char *src = cl_file_map_begin(fm);
> > +    const size_t sz = cl_file_map_size(fm);
> > +    program = clCreateProgramWithSource(ctx, 1, &src, &sz, &status);
> > +    cl_file_map_delete(fm);
> > +
> > +    if (status != CL_SUCCESS) {
> > +      fprintf(stderr, "error calling clCreateProgramWithSource\n");
> > +      goto error;
> > +    }
> > +    prevFileName = file_name;
> > +
> > +    OCL_CALL (clCompileProgram, program,
> > +                                1, &device, // num_devices & device_list
> > +                                NULL, // compile_options
> > +                                0, // num_input_headers
> > +                                NULL,
> > +                                NULL,
> > +                                NULL, NULL);
> > +   OCL_ASSERT(err==CL_SUCCESS);
> > +  cl_program input_programs[1] = {program};  program =
> > + clLinkProgram(ctx, 1, &device, link_opt, 1, input_programs, NULL,
> > NULL, &err);
> > +  OCL_ASSERT(program != NULL);
> > +  OCL_ASSERT(err == CL_SUCCESS);
> > +  }
> > +
> > +  /* Create a kernel from the program */  if (kernel)
> > +    clReleaseKernel(kernel);
> > +  kernel = clCreateKernel(program, kernel_name, &status);  if (status
> > + != CL_SUCCESS) {
> > +    fprintf(stderr, "error calling clCreateKernel\n");
> > +    goto error;
> > +  }
> > +
> > +exit:
> > +  free(ker_path);
> > +  cl_file_map_delete(fm);
> > +  return status;
> > +error:
> > +  prevFileName = NULL;
> > +  goto exit;
> > +}
> > +
> > +
> >  #define GET_PLATFORM_STR_INFO(LOWER_NAME, NAME) \
> >    { \
> >      size_t param_value_size; \
> > diff --git a/utests/utest_helper.hpp b/utests/utest_helper.hpp index
> > 3b17606..e6c8515 100644
> > --- a/utests/utest_helper.hpp
> > +++ b/utests/utest_helper.hpp
> > @@ -194,6 +194,10 @@ extern int cl_ocl_init(void);
> >  /* Init program and kernel for the test */  extern int
> > cl_kernel_init(const char *file_name,
> >                  const char *kernel_name, int format, const char *
> > build_opt);
> > +extern int cl_kernel_compile(const char *file_name, const char
> *kernel_name,
> > +                const char * compile_opt); extern int
> > +cl_kernel_link(const char *file_name, const char *kernel_name,
> > +                const char * link_opt);
> >
> >  /* Get the file path */
> >  extern char* cl_do_kiss_path(const char *file, cl_device_id device);
> > --
> > 1.9.1
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list