1 /* 2 * Copyright (c) 2011-2019, The University of Oxford. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 1. Redistributions of source code must retain the above copyright notice, 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the University of Oxford nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 * software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef OSKAR_VECTOR_TYPES_H_ 30 #define OSKAR_VECTOR_TYPES_H_ 31 32 /** 33 * @file oskar_vector_types.h 34 */ 35 36 #ifdef __CUDACC__ 37 /* Include the CUDA vector types header first, if we're compiling with nvcc. */ 38 # include <vector_types.h> 39 #endif 40 41 /* Memory alignment macros mirroring those used by CUDA. */ 42 #if !(defined(__VECTOR_TYPES_H__) || defined(__CUDACC__)) 43 # if defined(__GNUC__) 44 # define __align__(n) __attribute__((aligned(n))) 45 # elif defined(_MSC_VER) 46 # define __align__(n) __declspec(align(n)) 47 # endif 48 # if defined(__GNUC__) || defined(_WIN64) 49 # define __builtin_align__(a) __align__(a) 50 # else 51 # define __builtin_align__(a) 52 # endif 53 54 /** 55 * @brief Two-element structure (single precision). 56 * 57 * @details 58 * Structure used to hold data for a length-2 vector. 59 * This must be compatible with the CUDA float2 type. 60 */ 61 struct __builtin_align__(8) float2 { float x, y; }; 62 typedef struct float2 float2; 63 64 /** 65 * @brief Two-element structure (double precision). 66 * 67 * @details 68 * Structure used to hold data for a length-2 vector. 69 * This must be compatible with the CUDA double2 type. 70 */ 71 struct __builtin_align__(16) double2 { double x, y; }; 72 typedef struct double2 double2; 73 #endif 74 75 /** 76 * @brief Four-element complex structure (single precision). 77 * 78 * @details 79 * Structure used to hold data for a length-4 single precision complex vector. 80 * When used as a matrix, the elements should be interpreted as: 81 * 82 * ( a b ) 83 * ( c d ) 84 */ 85 struct __align__(32) float4c { float2 a, b, c, d; }; 86 typedef struct float4c float4c; 87 88 /** 89 * @brief Four-element complex structure (double precision). 90 * 91 * @details 92 * Structure used to hold data for a length-4 double precision complex vector. 93 * When used as a matrix, the elements should be interpreted as: 94 * 95 * ( a b ) 96 * ( c d ) 97 */ 98 struct __align__(64) double4c { double2 a, b, c, d; }; 99 typedef struct double4c double4c; 100 101 #endif /* include guard */ 102