|
| 1 | +/* ----------------------------------------------------------------- |
| 2 | + * Programmer(s): Daniel McGreer and Cody J. Balos @ LLNL |
| 3 | + * ----------------------------------------------------------------- |
| 4 | + * SUNDIALS Copyright Start |
| 5 | + * Copyright (c) 2002-2020, Lawrence Livermore National Security |
| 6 | + * and Southern Methodist University. |
| 7 | + * All rights reserved. |
| 8 | + * |
| 9 | + * See the top-level LICENSE and NOTICE files for details. |
| 10 | + * |
| 11 | + * SPDX-License-Identifier: BSD-3-Clause |
| 12 | + * SUNDIALS Copyright End |
| 13 | + * ----------------------------------------------------------------- |
| 14 | + * This is the header file for the hip implementation of the |
| 15 | + * NVECTOR module. |
| 16 | + * |
| 17 | + * Notes: |
| 18 | + * |
| 19 | + * - The definition of the generic N_Vector structure can be found |
| 20 | + * in the header file sundials_nvector.h. |
| 21 | + * |
| 22 | + * - The definitions of the types 'realtype' and 'sunindextype' can |
| 23 | + * be found in the header file sundials_types.h, and it may be |
| 24 | + * changed (at the configuration stage) according to the user's needs. |
| 25 | + * The sundials_types.h file also contains the definition |
| 26 | + * for the type 'booleantype'. |
| 27 | + * |
| 28 | + * - N_Vector arguments to arithmetic vector operations need not |
| 29 | + * be distinct. For example, the following call: |
| 30 | + * |
| 31 | + * N_VLinearSum_Hip(a,x,b,y,y); |
| 32 | + * |
| 33 | + * (which stores the result of the operation a*x+b*y in y) |
| 34 | + * is legal. |
| 35 | + * -----------------------------------------------------------------*/ |
| 36 | + |
| 37 | +#ifndef _NVECTOR_HIP_H |
| 38 | +#define _NVECTOR_HIP_H |
| 39 | + |
| 40 | +#include <stdio.h> |
| 41 | + |
| 42 | +#include <sundials/sundials_hip_policies.hpp> |
| 43 | +#include <sundials/sundials_memory.h> |
| 44 | +#include <sundials/sundials_nvector.h> |
| 45 | + |
| 46 | +#ifdef __cplusplus /* wrapper to enable C++ usage */ |
| 47 | +extern "C" { |
| 48 | +#endif |
| 49 | + |
| 50 | +/* |
| 51 | + * ----------------------------------------------------------------- |
| 52 | + * hip implementation of N_Vector |
| 53 | + * ----------------------------------------------------------------- |
| 54 | + */ |
| 55 | + |
| 56 | +struct _N_VectorContent_Hip |
| 57 | +{ |
| 58 | + sunindextype length; |
| 59 | + booleantype own_exec; |
| 60 | + booleantype own_helper; |
| 61 | + SUNMemory host_data; |
| 62 | + SUNMemory device_data; |
| 63 | + SUNHipExecPolicy* stream_exec_policy; |
| 64 | + SUNHipExecPolicy* reduce_exec_policy; |
| 65 | + SUNMemoryHelper mem_helper; |
| 66 | + void* priv; /* 'private' data */ |
| 67 | +}; |
| 68 | + |
| 69 | +typedef struct _N_VectorContent_Hip *N_VectorContent_Hip; |
| 70 | + |
| 71 | +/* |
| 72 | + * ----------------------------------------------------------------- |
| 73 | + * NVECTOR_HIP implementation specific functions |
| 74 | + * ----------------------------------------------------------------- |
| 75 | + */ |
| 76 | + |
| 77 | +SUNDIALS_EXPORT N_Vector N_VNew_Hip(sunindextype length); |
| 78 | +SUNDIALS_EXPORT N_Vector N_VNewManaged_Hip(sunindextype length); |
| 79 | +SUNDIALS_EXPORT N_Vector N_VNewWithMemHelp_Hip(sunindextype length, |
| 80 | + booleantype use_managed_mem, |
| 81 | + SUNMemoryHelper helper); |
| 82 | +SUNDIALS_EXPORT N_Vector N_VNewEmpty_Hip(); |
| 83 | +SUNDIALS_EXPORT N_Vector N_VMake_Hip(sunindextype length, |
| 84 | + realtype *h_vdata, |
| 85 | + realtype *d_vdata); |
| 86 | +SUNDIALS_EXPORT N_Vector N_VMakeManaged_Hip(sunindextype length, |
| 87 | + realtype *vdata); |
| 88 | +SUNDIALS_EXPORT void N_VSetHostArrayPointer_Hip(realtype* h_vdata, N_Vector v); |
| 89 | +SUNDIALS_EXPORT booleantype N_VIsManagedMemory_Hip(N_Vector x); |
| 90 | +SUNDIALS_EXPORT int N_VSetKernelExecPolicy_Hip(N_Vector x, |
| 91 | + SUNHipExecPolicy* stream_exec_policy, |
| 92 | + SUNHipExecPolicy* reduce_exec_policy); |
| 93 | +SUNDIALS_EXPORT void N_VCopyToDevice_Hip(N_Vector v); |
| 94 | +SUNDIALS_EXPORT void N_VCopyFromDevice_Hip(N_Vector v); |
| 95 | +SUNDIALS_EXPORT void N_VPrint_Hip(N_Vector v); |
| 96 | +SUNDIALS_EXPORT void N_VPrintFile_Hip(N_Vector v, FILE *outfile); |
| 97 | + |
| 98 | +SUNDIALS_STATIC_INLINE |
| 99 | +sunindextype N_VGetLength_Hip(N_Vector x) |
| 100 | +{ |
| 101 | + N_VectorContent_Hip content = (N_VectorContent_Hip)x->content; |
| 102 | + return content->length; |
| 103 | +} |
| 104 | + |
| 105 | +SUNDIALS_STATIC_INLINE |
| 106 | +realtype *N_VGetHostArrayPointer_Hip(N_Vector x) |
| 107 | +{ |
| 108 | + N_VectorContent_Hip content = (N_VectorContent_Hip)x->content; |
| 109 | + return(content->host_data == NULL ? NULL : (realtype*)content->host_data->ptr); |
| 110 | +} |
| 111 | + |
| 112 | +SUNDIALS_STATIC_INLINE |
| 113 | +realtype *N_VGetDeviceArrayPointer_Hip(N_Vector x) |
| 114 | +{ |
| 115 | + N_VectorContent_Hip content = (N_VectorContent_Hip)x->content; |
| 116 | + return(content->device_data == NULL ? NULL : (realtype*)content->device_data->ptr); |
| 117 | +} |
| 118 | + |
| 119 | +/* |
| 120 | + * ----------------------------------------------------------------- |
| 121 | + * NVECTOR API functions |
| 122 | + * ----------------------------------------------------------------- |
| 123 | + */ |
| 124 | + |
| 125 | +SUNDIALS_EXPORT N_Vector N_VCloneEmpty_Hip(N_Vector w); |
| 126 | +SUNDIALS_EXPORT N_Vector N_VClone_Hip(N_Vector w); |
| 127 | +SUNDIALS_EXPORT void N_VDestroy_Hip(N_Vector v); |
| 128 | +SUNDIALS_EXPORT void N_VSpace_Hip(N_Vector v, sunindextype *lrw, sunindextype *liw); |
| 129 | + |
| 130 | +/* standard vector operations */ |
| 131 | +SUNDIALS_EXPORT void N_VLinearSum_Hip(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z); |
| 132 | +SUNDIALS_EXPORT void N_VConst_Hip(realtype c, N_Vector z); |
| 133 | +SUNDIALS_EXPORT void N_VProd_Hip(N_Vector x, N_Vector y, N_Vector z); |
| 134 | +SUNDIALS_EXPORT void N_VDiv_Hip(N_Vector x, N_Vector y, N_Vector z); |
| 135 | +SUNDIALS_EXPORT void N_VScale_Hip(realtype c, N_Vector x, N_Vector z); |
| 136 | +SUNDIALS_EXPORT void N_VAbs_Hip(N_Vector x, N_Vector z); |
| 137 | +SUNDIALS_EXPORT void N_VInv_Hip(N_Vector x, N_Vector z); |
| 138 | +SUNDIALS_EXPORT void N_VAddConst_Hip(N_Vector x, realtype b, N_Vector z); |
| 139 | +SUNDIALS_EXPORT realtype N_VDotProd_Hip(N_Vector x, N_Vector y); |
| 140 | +SUNDIALS_EXPORT realtype N_VMaxNorm_Hip(N_Vector x); |
| 141 | +SUNDIALS_EXPORT realtype N_VWrmsNorm_Hip(N_Vector x, N_Vector w); |
| 142 | +SUNDIALS_EXPORT realtype N_VWrmsNormMask_Hip(N_Vector x, N_Vector w, N_Vector id); |
| 143 | +SUNDIALS_EXPORT realtype N_VMin_Hip(N_Vector x); |
| 144 | +SUNDIALS_EXPORT realtype N_VWL2Norm_Hip(N_Vector x, N_Vector w); |
| 145 | +SUNDIALS_EXPORT realtype N_VL1Norm_Hip(N_Vector x); |
| 146 | +SUNDIALS_EXPORT void N_VCompare_Hip(realtype c, N_Vector x, N_Vector z); |
| 147 | +SUNDIALS_EXPORT booleantype N_VInvTest_Hip(N_Vector x, N_Vector z); |
| 148 | +SUNDIALS_EXPORT booleantype N_VConstrMask_Hip(N_Vector c, N_Vector x, N_Vector m); |
| 149 | +SUNDIALS_EXPORT realtype N_VMinQuotient_Hip(N_Vector num, N_Vector denom); |
| 150 | + |
| 151 | +/* fused vector operations */ |
| 152 | +SUNDIALS_EXPORT int N_VLinearCombination_Hip(int nvec, realtype* c, N_Vector* X, |
| 153 | + N_Vector Z); |
| 154 | +SUNDIALS_EXPORT int N_VScaleAddMulti_Hip(int nvec, realtype* c, N_Vector X, |
| 155 | + N_Vector* Y, N_Vector* Z); |
| 156 | +SUNDIALS_EXPORT int N_VDotProdMulti_Hip(int nvec, N_Vector x, N_Vector* Y, |
| 157 | + realtype* dotprods); |
| 158 | + |
| 159 | +/* vector array operations */ |
| 160 | +SUNDIALS_EXPORT int N_VLinearSumVectorArray_Hip(int nvec, |
| 161 | + realtype a, N_Vector* X, |
| 162 | + realtype b, N_Vector* Y, |
| 163 | + N_Vector* Z); |
| 164 | +SUNDIALS_EXPORT int N_VScaleVectorArray_Hip(int nvec, realtype* c, N_Vector* X, |
| 165 | + N_Vector* Z); |
| 166 | +SUNDIALS_EXPORT int N_VConstVectorArray_Hip(int nvec, realtype c, N_Vector* Z); |
| 167 | +SUNDIALS_EXPORT int N_VScaleAddMultiVectorArray_Hip(int nvec, int nsum, |
| 168 | + realtype* a, N_Vector* X, |
| 169 | + N_Vector** Y, N_Vector** Z); |
| 170 | +SUNDIALS_EXPORT int N_VLinearCombinationVectorArray_Hip(int nvec, int nsum, |
| 171 | + realtype* c, |
| 172 | + N_Vector** X, |
| 173 | + N_Vector* Z); |
| 174 | +SUNDIALS_EXPORT int N_VWrmsNormVectorArray_Hip(int nvec, N_Vector* X, |
| 175 | + N_Vector* W, realtype* nrm); |
| 176 | +SUNDIALS_EXPORT int N_VWrmsNormMaskVectorArray_Hip(int nvec, N_Vector* X, |
| 177 | + N_Vector* W, N_Vector id, |
| 178 | + realtype* nrm); |
| 179 | + |
| 180 | +/* OPTIONAL local reduction kernels (no parallel communication) */ |
| 181 | +SUNDIALS_EXPORT realtype N_VWSqrSumLocal_Hip(N_Vector x, N_Vector w); |
| 182 | +SUNDIALS_EXPORT realtype N_VWSqrSumMaskLocal_Hip(N_Vector x, N_Vector w, N_Vector id); |
| 183 | + |
| 184 | +/* OPTIONAL XBraid interface operations */ |
| 185 | +SUNDIALS_EXPORT int N_VBufSize_Hip(N_Vector x, sunindextype *size); |
| 186 | +SUNDIALS_EXPORT int N_VBufPack_Hip(N_Vector x, void *buf); |
| 187 | +SUNDIALS_EXPORT int N_VBufUnpack_Hip(N_Vector x, void *buf); |
| 188 | + |
| 189 | +/* OPTIONAL operations for debugging */ |
| 190 | +SUNDIALS_EXPORT void N_VPrint_Hip(N_Vector v); |
| 191 | +SUNDIALS_EXPORT void N_VPrintFile_Hip(N_Vector v, FILE *outfile); |
| 192 | + |
| 193 | +/* |
| 194 | + * ----------------------------------------------------------------- |
| 195 | + * Enable / disable fused vector operations |
| 196 | + * ----------------------------------------------------------------- |
| 197 | + */ |
| 198 | + |
| 199 | +SUNDIALS_EXPORT int N_VEnableFusedOps_Hip(N_Vector v, booleantype tf); |
| 200 | + |
| 201 | +SUNDIALS_EXPORT int N_VEnableLinearCombination_Hip(N_Vector v, booleantype tf); |
| 202 | +SUNDIALS_EXPORT int N_VEnableScaleAddMulti_Hip(N_Vector v, booleantype tf); |
| 203 | +SUNDIALS_EXPORT int N_VEnableDotProdMulti_Hip(N_Vector v, booleantype tf); |
| 204 | + |
| 205 | +SUNDIALS_EXPORT int N_VEnableLinearSumVectorArray_Hip(N_Vector v, booleantype tf); |
| 206 | +SUNDIALS_EXPORT int N_VEnableScaleVectorArray_Hip(N_Vector v, booleantype tf); |
| 207 | +SUNDIALS_EXPORT int N_VEnableConstVectorArray_Hip(N_Vector v, booleantype tf); |
| 208 | +SUNDIALS_EXPORT int N_VEnableWrmsNormVectorArray_Hip(N_Vector v, booleantype tf); |
| 209 | +SUNDIALS_EXPORT int N_VEnableWrmsNormMaskVectorArray_Hip(N_Vector v, booleantype tf); |
| 210 | +SUNDIALS_EXPORT int N_VEnableScaleAddMultiVectorArray_Hip(N_Vector v, booleantype tf); |
| 211 | +SUNDIALS_EXPORT int N_VEnableLinearCombinationVectorArray_Hip(N_Vector v, booleantype tf); |
| 212 | + |
| 213 | +#ifdef __cplusplus |
| 214 | +} |
| 215 | +#endif |
| 216 | + |
| 217 | +#endif |
0 commit comments