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

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

#include "opencl_errors_map.hpp"
Include dependency graph for example.cpp:

Go to the source code of this file.

Functions

std::string dirname (std::string path)
 Return the directory part of path. More...
 
std::string error_name (cl_int code)
 Return the error name corresponding to the error code. More...
 
std::string file_to_string (std::string filename)
 Read the file and return its content to a string. If failed then print a error message and exit. More...
 
cl::Device get_device (unsigned int platform_i, unsigned int device_i)
 Return the given device of the given platform OpenCL, or exit if doesn't exists. More...
 
void print_error (cl_int code, std::string 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 device, bool debug, const std::string &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 std::map< int32_t, std::string > errors_map
 List of all error codes and names extracted from /usr/include/CL/cl.h. 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.cpp.

Function Documentation

◆ dirname()

std::string dirname ( std::string  path)

Return the directory part of path.

Definition at line 224 of file example.cpp.

◆ error_name()

std::string error_name ( cl_int  code)

Return the error name corresponding to the error code.

Definition at line 177 of file example.cpp.

◆ file_to_string()

std::string file_to_string ( std::string  filename)

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

Definition at line 187 of file example.cpp.

◆ get_device()

cl::Device get_device ( unsigned int  platform_i,
unsigned int  device_i 
)

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

Parameters
platform_i
device_i
Returns
OpenCL device

Definition at line 204 of file example.cpp.

◆ 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 398 of file example.cpp.

◆ print_error()

void print_error ( cl_int  code,
std::string  message = "" 
)

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

Definition at line 241 of file example.cpp.

◆ run_example()

void run_example ( unsigned int  nb_work_group,
unsigned int  nb_work_items_by_work_group,
cl::Device  device,
bool  debug,
const std::string &  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 257 of file example.cpp.

Variable Documentation

◆ errors_map

const std::map<int32_t, std::string> errors_map

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

Definition at line 35 of file example.cpp.