<commit_before>/*
 * Copyright (c) ICG. All rights reserved.
 *
 * Institute for Computer Graphics and Vision
 * Graz University of Technology / Austria
 *
 *
 * This software is distributed WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the above copyright notices for more information.
 *
 *
 * Project     : ImageUtilities
 * Module      : global
 * Class       : none
 * Language    : C/CUDA
 * Description : Common cuda functionality that might also be interesting for other applications.
 *
 * Author     : <NAME>
 * EMail      : <EMAIL>
 *
 */

#ifndef IU_CUTIL_H
#define IU_CUTIL_H

#ifdef WIN32
  #undef max
  #undef min
  #define NOMINMAX
#endif

//#ifdef __CUDACC__ // only include this include in cuda files (seen by nvcc)
#include <cutil_math.h>
//#endif

#include <driver_types.h>
#include "iucore/coredefs.h"

// including some common device functions
#include "common/vectormath_kernels.cuh"
#include "common/derivative_kernels.cuh"
#include "common/bsplinetexture_kernels.cuh"
//#include "common/bind_textures.cuh"

///// SIMPLE MIN MAX HELPERS
#ifndef __CUDACC__
template<typename Type>
inline Type IUMIN(Type a, Type b) {return (a<b)?a:b;}

template<typename Type>
inline Type IUMAX(Type a, Type b) {return (a>b)?a:b;}
#else
template<typename Type>
inline __host__ __device__ Type IUMIN(Type a, Type b) {return min(a,b);}

template<typename Type>
inline __host__ __device__ Type IUMAX(Type a, Type b) {return max(a,b);}
#endif

namespace iu {
template<typename Type>
inline __host__ __device__ Type sqr(Type a) {return a*a;}
}

// includes for time measurements
#ifdef WIN32
  #include <time.h>
  #include <windows.h>
#else
  #include <sys/time.h>
#endif

//// ERROR CHECKS ////////////////////////////////////////////

#include <stdio.h>

#define IU_CUDACALL(err) iu::cudaCall(err, __FILE__, __LINE__ );

#define IU_CUDA_CHECK() \
{ \<commit_msg>as sqrtf(0) gives us nan as result and  IUMAX(1e-6f,a) and IUMAX(a,1e-6f) give different results when a=nan we do some sanity checks if one of the arguments given to IUMAX or IUMIN is nan or inf -> then automatically the other value is taken.<commit_after>/*
 * Copyright (c) ICG. All rights reserved.
 *
 * Institute for Computer Graphics and Vision
 * Graz University of Technology / Austria
 *
 *
 * This software is distributed WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the above copyright notices for more information.
 *
 *
 * Project     : ImageUtilities
 * Module      : global
 * Class       : none
 * Language    : C/CUDA
 * Description : Common cuda functionality that might also be interesting for other applications.
 *
 * Author     : <NAME>
 * EMail      : <EMAIL>
 *
 */

#ifndef IU_CUTIL_H
#define IU_CUTIL_H

#ifdef WIN32
  #undef max
  #undef min
  #define NOMINMAX
#endif

//#ifdef __CUDACC__ // only include this include in cuda files (seen by nvcc)
#include <cutil_math.h>
//#endif

#include <driver_types.h>
#include "iucore/coredefs.h"

// including some common device functions
#include "common/vectormath_kernels.cuh"
#include "common/derivative_kernels.cuh"
#include "common/bsplinetexture_kernels.cuh"
//#include "common/bind_textures.cuh"

///// SIMPLE MIN MAX HELPERS
//#ifndef __CUDACC__
template<typename Type>
inline __host__ __device__ Type IUMIN(Type a, Type b)
{
  if (isnan(a) || isinf(a))
    return b;
  if (isnan(b) || isinf(b))
    return a;
  return a<b ? a : b;
}

template<typename Type>
inline __host__ __device__ Type IUMAX(Type a, Type b)
{
  if (isnan(a) || isinf(a))
    return b;
  if (isnan(b) || isinf(b))
    return a;
  return a>b ? a : b;
}

//#else
//template<typename Type>
//inline __host__ __device__ Type IUMIN(Type a, Type b) {return min(a,b);}

//template<typename Type>
//inline __host__ __device__ Type IUMAX(Type a, Type b) {return max(a,b);}
//#endif

namespace iu {
template<typename Type>
inline __host__ __device__ Type sqr(Type a) {return a*a;}
}

// includes for time measurements
#ifdef WIN32
  #include <time.h>
  #include <windows.h>
#else
  #include <sys/time.h>
#endif

//// ERROR CHECKS ////////////////////////////////////////////

#include <stdio.h>

#define IU_CUDACALL(err) iu::cudaCall(err, __FILE__, __LINE__ );

#define IU_CUDA_CHECK() \
{ \
{'fraction_non_alphanumeric': 0.13063477460901565, 'fraction_numerical': 0.002989880404783809, 'mean_word_length': 3.553926701570681, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3193395', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1455, 'n_words': 477}