Blame ocl_icd_debug.h

Packit Service e6cf14
/**
Packit Service e6cf14
Copyright (c) 2012, Vincent Danjean <Vincent.Danjean@ens-lyon.org>
Packit Service e6cf14
All rights reserved.
Packit Service e6cf14
      
Packit Service e6cf14
Redistribution and use in source and binary forms, with or without
Packit Service e6cf14
modification, are permitted provided that the following conditions are met:
Packit Service e6cf14
    
Packit Service e6cf14
1. Redistributions of source code must retain the above copyright notice, this
Packit Service e6cf14
   list of conditions and the following disclaimer.
Packit Service e6cf14
2. Redistributions in binary form must reproduce the above copyright notice,
Packit Service e6cf14
   this list of conditions and the following disclaimer in the documentation
Packit Service e6cf14
   and/or other materials provided with the distribution.
Packit Service e6cf14
        
Packit Service e6cf14
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Packit Service e6cf14
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Packit Service e6cf14
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Packit Service e6cf14
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
Packit Service e6cf14
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Packit Service e6cf14
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Packit Service e6cf14
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Packit Service e6cf14
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit Service e6cf14
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Packit Service e6cf14
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit Service e6cf14
*/
Packit Service e6cf14
#ifndef OCL_ICD_LOADER_DEBUG_H
Packit Service e6cf14
#define OCL_ICD_LOADER_DEBUG_H
Packit Service e6cf14
Packit Service e6cf14
#ifdef DEBUG_OCL_ICD_PROVIDE_DUMP_FIELD
Packit Service e6cf14
#  pragma GCC diagnostic push
Packit Service e6cf14
#  pragma GCC diagnostic ignored "-Wcpp"
Packit Service e6cf14
#  define CL_USE_DEPRECATED_OPENCL_1_1_APIS
Packit Service e6cf14
#endif
Packit Service e6cf14
#include <CL/cl.h>
Packit Service e6cf14
#ifdef DEBUG_OCL_ICD_PROVIDE_DUMP_FIELD
Packit Service e6cf14
#  pragma GCC diagnostic pop
Packit Service e6cf14
#endif
Packit Service e6cf14
Packit Service e6cf14
#pragma GCC visibility push(hidden)
Packit Service e6cf14
Packit Service e6cf14
#include "config.h"
Packit Service e6cf14
Packit Service e6cf14
#define D_ALWAYS 0
Packit Service e6cf14
#define D_WARN 1
Packit Service e6cf14
#define D_LOG 2
Packit Service e6cf14
#define D_TRACE 4
Packit Service e6cf14
#define D_DUMP 8
Packit Service e6cf14
#ifdef DEBUG_OCL_ICD
Packit Service e6cf14
#  pragma GCC visibility push(default)
Packit Service e6cf14
#  include <stdio.h>
Packit Service e6cf14
#  include <stdlib.h>
Packit Service e6cf14
#  pragma GCC visibility pop
Packit Service e6cf14
extern int debug_ocl_icd_mask;
Packit Service e6cf14
#  define debug(mask, fmt, ...) do {\
Packit Service e6cf14
	if (((mask)==D_ALWAYS) || (debug_ocl_icd_mask & (mask))) {			\
Packit Service e6cf14
		fprintf(stderr, "ocl-icd(%s:%i): %s: " fmt "\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
Packit Service e6cf14
	} \
Packit Service e6cf14
   } while(0)
Packit Service e6cf14
#  define RETURN(val) do { \
Packit Service e6cf14
	__typeof__(val) ret=(val); \
Packit Service e6cf14
	debug(D_TRACE, "return: %ld/0x%lx", (long)ret, (long)ret);	\
Packit Service e6cf14
	return ret; \
Packit Service e6cf14
   } while(0)
Packit Service e6cf14
#  define RETURN_STR(val) do { \
Packit Service e6cf14
	char* _ret=(char*)(val);		\
Packit Service e6cf14
	debug(D_TRACE, "return: %s", _ret);	\
Packit Service e6cf14
	return _ret; \
Packit Service e6cf14
   } while(0)
Packit Service e6cf14
#  ifdef DEBUG_OCL_ICD_PROVIDE_DUMP_FIELD
Packit Service e6cf14
#    pragma GCC diagnostic push
Packit Service e6cf14
#      pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Packit Service e6cf14
typedef __typeof__(clGetExtensionFunctionAddress) *clGEFA_t;
Packit Service e6cf14
#    pragma GCC diagnostic pop
Packit Service e6cf14
void dump_platform(clGEFA_t f, cl_platform_id pid);
Packit Service e6cf14
#  endif
Packit Service e6cf14
static inline void debug_init(void) {
Packit Service e6cf14
  static int done=0;
Packit Service e6cf14
  if (!done) {
Packit Service e6cf14
    char *debug=getenv("OCL_ICD_DEBUG");
Packit Service e6cf14
    if (debug) {
Packit Service e6cf14
      debug_ocl_icd_mask=atoi(debug);
Packit Service e6cf14
      if (*debug == 0)
Packit Service e6cf14
        debug_ocl_icd_mask=1;
Packit Service e6cf14
    }
Packit Service e6cf14
    done=1;
Packit Service e6cf14
  }
Packit Service e6cf14
}
Packit Service e6cf14
Packit Service e6cf14
#  define dump_field(pid, f, name) \
Packit Service e6cf14
    debug(D_ALWAYS, "%40s=%p [%p/%p]", #name, pid->dispatch->name, f(#name), ((long)(pid->dispatch->clGetExtensionFunctionAddressForPlatform)>10)?pid->dispatch->clGetExtensionFunctionAddressForPlatform(pid, #name):NULL)
Packit Service e6cf14
Packit Service e6cf14
#else
Packit Service e6cf14
#  define debug(...) (void)0
Packit Service e6cf14
#  define RETURN(val) return (val)
Packit Service e6cf14
#  define RETURN_STR(val) return (val)
Packit Service e6cf14
#  define debug_init() (void)0
Packit Service e6cf14
#endif
Packit Service e6cf14
Packit Service e6cf14
#define debug_trace() debug(D_TRACE, "Entering")
Packit Service e6cf14
Packit Service e6cf14
#pragma GCC visibility pop
Packit Service e6cf14
Packit Service e6cf14
#endif