assertOpenCL  September 19, 2018
Classes | Functions | Variables
example.c File Reference

Simple C example to show how run a kernel with assert*() and PRINT*() macros and test them. More...

#include "opencl_errors_map.h"
Include dependency graph for example.c:

Go to the source code of this file.

Classes

struct  error_name_t
 

Functions

char * dirname_alloc (const char *path)
 Return the directory part of path in a (new allocated) string. More...
 
const char * error_name (cl_int code)
 Return the error name corresponding to the error code. More...
 
char * file_to_alloc_string (const char *filename)
 Read the file and return its content to a (new allocated) string. If failed then print a error message and exit. More...
 
cl_device_id get_device_id (unsigned int platform_i, unsigned int device_i)
 Return the given id device of the given platform OpenCL, or exit if doesn't exists. More...
 
char * get_device_info_alloc_string (cl_device_id device_id, cl_device_info param_name)
 Return a (new allocated) string corresponding to device info parameter. More...
 
void print_error (cl_int code, const char *message)
 If code != 0 then print an error message corresponding to the error code. More...
 
void run_example (unsigned int nb_work_group, unsigned int nb_work_items_by_work_group, cl_device_id device_id, bool debug, const char *path)
 Run the kernel ../kernel/example.cl. More...
 
int main (int argc, const char *const argv[])
 Get the optional parameter –device platform:device and run the kernel ../kernel/example.cl. More...
 

Variables

const error_name_t errors_map [61]
 List of all error codes and names extracted from /usr/include/CL/cl.h. More...
 
const unsigned int errors_map_size = 61
 Number of elements in errors_map. More...
 

Detailed Description

Simple C example to show how run a kernel with assert*() and PRINT*() macros and test them.

Piece of assertOpenCL — GPLv3 — Copyright (C) 2018 Olivier Pirson — http://www.opimedia.be/ — September 19, 2018

Definition in file example.c.

Function Documentation

◆ dirname_alloc()

char * dirname_alloc ( const char *  path)

Return the directory part of path in a (new allocated) string.

Definition at line 127 of file example.c.

◆ error_name()

std::string error_name ( cl_int  code)

Return the error name corresponding to the error code.

Definition at line 167 of file example.c.

◆ file_to_alloc_string()

char * file_to_alloc_string ( const char *  filename)

Read the file and return its content to a (new allocated) string. If failed then print a error message and exit.

Definition at line 179 of file example.c.

◆ get_device_id()

cl_device_id get_device_id ( unsigned int  platform_i,
unsigned int  device_i 
)

Return the given id device of the given platform OpenCL, or exit if doesn't exists.

Parameters
platform_i
device_i
Returns
OpenCL device id

Definition at line 209 of file example.c.

◆ get_device_info_alloc_string()

char * get_device_info_alloc_string ( cl_device_id  device_id,
cl_device_info  param_name 
)

Return a (new allocated) string corresponding to device info parameter.

Definition at line 255 of file example.c.

◆ main()

int main ( int  argc,
const char *const  argv[] 
)

Get the optional parameter –device platform:device and run the kernel ../kernel/example.cl.

Definition at line 486 of file example.c.

◆ print_error()

void print_error ( cl_int  code,
const char *  message 
)

If code != 0 then print an error message corresponding to the error code.

Definition at line 274 of file example.c.

◆ run_example()

void run_example ( unsigned int  nb_work_group,
unsigned int  nb_work_items_by_work_group,
cl_device_id  device_id,
bool  debug,
const char *  path 
)

Run the kernel ../kernel/example.cl.

If debug then run the kernel in debug mode, else run the kernel with the macro NDEBUG defined.

Definition at line 288 of file example.c.

Variable Documentation

◆ errors_map

const error_name_t errors_map[61]

List of all error codes and names extracted from /usr/include/CL/cl.h.

Definition at line 43 of file example.c.

◆ errors_map_size

const unsigned int errors_map_size = 61

Number of elements in errors_map.

Definition at line 51 of file example.c.