1 /* 2 * Copyright (c) 2011-2020, The OSKAR Developers. 3 * See the LICENSE file at the top-level directory of this distribution. 4 */ 5 6 #ifndef OSKAR_GLOBAL_H_ 7 #define OSKAR_GLOBAL_H_ 8 9 /** 10 * @brief 11 * Enumerator to define OSKAR common error conditions. 12 * 13 * @details 14 * This enumerator defines common error conditions returned by functions 15 * in the OSKAR library. 16 * 17 * All OSKAR error codes are negative. 18 * Positive error codes indicate CUDA run-time execution errors. 19 */ 20 enum OSKAR_ERROR_CODES 21 { 22 /* Code zero means no error. */ 23 OSKAR_ERR_EOF = -1, 24 OSKAR_ERR_FILE_IO = -2, 25 OSKAR_ERR_INVALID_ARGUMENT = -3, 26 OSKAR_ERR_FUNCTION_NOT_AVAILABLE = -4, 27 OSKAR_ERR_OUT_OF_RANGE = -5, 28 OSKAR_ERR_MEMORY_ALLOC_FAILURE = -6, 29 OSKAR_ERR_MEMORY_COPY_FAILURE = -7, 30 OSKAR_ERR_MEMORY_NOT_ALLOCATED = -8, 31 OSKAR_ERR_TYPE_MISMATCH = -9, 32 OSKAR_ERR_LOCATION_MISMATCH = -10, 33 OSKAR_ERR_DIMENSION_MISMATCH = -11, 34 OSKAR_ERR_VALUE_MISMATCH = -12, 35 OSKAR_ERR_BAD_DATA_TYPE = -13, 36 OSKAR_ERR_BAD_LOCATION = -14, 37 OSKAR_ERR_BAD_UNITS = -15, 38 OSKAR_ERR_CUDA_NOT_AVAILABLE = -16, 39 OSKAR_ERR_OPENCL_NOT_AVAILABLE = -17, 40 OSKAR_ERR_KERNEL_LAUNCH_FAILURE = -18, 41 OSKAR_ERR_COMPUTE_DEVICES = -19, 42 43 /* The following enumerators are under review... */ 44 OSKAR_ERR_SPLINE_COEFF_FAIL = -20, 45 OSKAR_ERR_SPLINE_EVAL_FAIL = -21, 46 OSKAR_ERR_ELLIPSE_FIT_FAILED = -22, 47 OSKAR_ERR_SETTINGS_TELESCOPE = -23, 48 OSKAR_ERR_SETUP_FAIL = -24, 49 OSKAR_ERR_SETUP_FAIL_SKY = -25, 50 OSKAR_ERR_SETUP_FAIL_TELESCOPE = -26, 51 OSKAR_ERR_SETUP_FAIL_TELESCOPE_ENTRIES_MISMATCH = -27, 52 OSKAR_ERR_SETUP_FAIL_TELESCOPE_CONFIG_FILE_MISSING = -28, 53 OSKAR_ERR_BAD_SKY_FILE = -29, 54 OSKAR_ERR_BAD_POINTING_FILE = -30, 55 OSKAR_ERR_BAD_COORD_FILE = -31, 56 OSKAR_ERR_BAD_GSM_FILE = -32, 57 OSKAR_ERR_FFT_FAILED = -33 58 59 /* 60 * Codes -75 to -99 are reserved for settings errors. 61 * 62 * Codes -100 to -125 are reserved for binary format errors. 63 * See oskar_binary.h 64 */ 65 }; 66 67 /** 68 * @brief 69 * Enumerator for use with bool flags. 70 */ 71 enum OSKAR_BOOL 72 { 73 OSKAR_FALSE = 0, 74 OSKAR_TRUE = 1 75 }; 76 77 /** 78 * @brief 79 * Enumerator to specify length units (metres or wavelengths). 80 */ 81 enum OSKAR_LENGTH 82 { 83 OSKAR_METRES = 0, 84 OSKAR_WAVELENGTHS = 1 85 }; 86 87 /** 88 * @brief 89 * Enumerator to define type of coordinate values. 90 */ 91 enum OSKAR_COORD_TYPE 92 { 93 OSKAR_COORDS_REL_DIR, 94 OSKAR_COORDS_ENU_DIR, 95 OSKAR_COORDS_RADEC, 96 OSKAR_COORDS_HADEC, 97 OSKAR_COORDS_AZEL, 98 OSKAR_COORDS_GALACTIC 99 }; 100 101 /* Macros used to prevent Eclipse from complaining about unknown CUDA syntax, 102 * and a few other things. */ 103 #ifdef __CDT_PARSER__ 104 #define __global__ 105 #define __device__ 106 #define __host__ 107 #define __shared__ 108 #define __constant__ 109 #define __forceinline__ 110 #define __launch_bounds__(...) 111 #define OSKAR_CUDAK_CONF(...) 112 #define OSKAR_HAVE_CUDA 113 #define OSKAR_HAVE_OPENCL 114 #define OSKAR_HAVE_HDF5 115 #define __CUDACC__ 116 #define __CUDA_ARCH__ 300 117 #define _OPENMP 118 #define OSKAR_CUDA_KERNEL(NAME) 119 #define OSKAR_VERSION_STR "OSKAR_VERSION_ERROR" 120 #define OSKAR_VERSION 0x999999 121 #else 122 #define OSKAR_CUDAK_CONF(...) <<< __VA_ARGS__ >>> 123 #endif 124 125 126 /* Detect Windows platform. */ 127 #if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__)) 128 # define OSKAR_OS_WIN32 129 #endif 130 #if (defined(WIN64) || defined(_WIN64) || defined(__WIN64__)) 131 # define OSKAR_OS_WIN64 132 #endif 133 134 /* http://goo.gl/OUEZfb */ 135 #if (defined(OSKAR_OS_WIN32) || defined(OSKAR_OS_WIN64)) 136 #define OSKAR_OS_WIN 137 #elif defined __APPLE__ 138 #include "TargetConditionals.h" 139 #if TARGET_OS_MAC 140 #define OSKAR_OS_MAC 141 #endif 142 #elif (defined(__linux__) || defined(__linux)) 143 #define OSKAR_OS_LINUX 144 #elif (defined(__unix__) || defined(__unix)) 145 #define OSKAR_OS_UNIX 146 #else 147 #error Unknown OS type detected! 148 #endif 149 150 /* 151 * Macro used to export public functions. 152 * Note: should only be needed in header files. 153 * 154 * The modifier enables the function to be exported by the library so that 155 * it can be used by other applications. 156 * 157 * Usage examples: 158 * OSKAR_EXPORT void foo(); 159 * OSKAR_EXPORT double add(double a, double b); 160 * 161 * For more information see: 162 * http://msdn.microsoft.com/en-us/library/a90k134d(v=VS.90).aspx 163 */ 164 #ifndef OSKAR_DECL_EXPORT 165 # ifdef OSKAR_OS_WIN 166 # define OSKAR_DECL_EXPORT __declspec(dllexport) 167 # elif __GNUC__ >= 4 168 # define OSKAR_DECL_EXPORT __attribute__((visibility ("default"))) 169 # else 170 # define OSKAR_DECL_EXPORT 171 # endif 172 #endif 173 #ifndef OSKAR_DECL_IMPORT 174 # ifdef OSKAR_OS_WIN 175 # define OSKAR_DECL_IMPORT __declspec(dllimport) 176 # elif __GNUC__ >= 4 177 # define OSKAR_DECL_IMPORT __attribute__((visibility ("default"))) 178 # else 179 # define OSKAR_DECL_IMPORT 180 # endif 181 #endif 182 183 #ifdef oskar_EXPORTS 184 # define OSKAR_EXPORT OSKAR_DECL_EXPORT 185 #else 186 # define OSKAR_EXPORT OSKAR_DECL_IMPORT 187 #endif 188 #ifdef oskar_apps_EXPORTS 189 # define OSKAR_APPS_EXPORT OSKAR_DECL_EXPORT 190 #else 191 # define OSKAR_APPS_EXPORT OSKAR_DECL_IMPORT 192 #endif 193 194 195 /* OSKAR_INLINE macro. */ 196 #ifdef __CUDA_ARCH__ 197 #define OSKAR_INLINE __device__ __forceinline__ 198 #elif __STDC_VERSION__ >= 199901L || defined(__cplusplus) 199 #define OSKAR_INLINE static inline 200 #else 201 #define OSKAR_INLINE static 202 #endif 203 204 205 /* RESTRICT macro. */ 206 #if defined(__cplusplus) && defined(__GNUC__) 207 #define RESTRICT __restrict__ 208 #elif defined(_MSC_VER) 209 #define RESTRICT __restrict 210 #elif !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L 211 #define RESTRICT 212 #else 213 #define RESTRICT restrict 214 #endif 215 216 217 #endif /* include guard */ 218