diff --git a/doc/shared/sunadaptcontroller/SUNAdaptController_Description.rst b/doc/shared/sunadaptcontroller/SUNAdaptController_Description.rst index acea4a0790..5943de430f 100644 --- a/doc/shared/sunadaptcontroller/SUNAdaptController_Description.rst +++ b/doc/shared/sunadaptcontroller/SUNAdaptController_Description.rst @@ -59,14 +59,14 @@ function pointers to the various controller operations, and is defined as struct _generic_SUNAdaptController_Ops { SUNAdaptController_Type (*getid)(SUNAdaptController C); - int (*destroy)(SUNAdaptController C); - int (*estimatestep)(SUNAdaptController C, sunrealtype h, int p, sunrealtype dsm, sunrealtype* hnew); - int (*reset)(SUNAdaptController C); - int (*setdefaults)(SUNAdaptController C); - int (*write)(SUNAdaptController C, FILE* fptr); - int (*seterrorbias)(SUNAdaptController C, sunrealtype bias); - int (*updateh)(SUNAdaptController C, sunrealtype h, sunrealtype dsm); - int (*space)(SUNAdaptController C, long int *lenrw, long int *leniw); + SUNErrCode (*destroy)(SUNAdaptController C); + SUNErrCode (*estimatestep)(SUNAdaptController C, sunrealtype h, int p, sunrealtype dsm, sunrealtype* hnew); + SUNErrCode (*reset)(SUNAdaptController C); + SUNErrCode (*setdefaults)(SUNAdaptController C); + SUNErrCode (*write)(SUNAdaptController C, FILE* fptr); + SUNErrCode (*seterrorbias)(SUNAdaptController C, sunrealtype bias); + SUNErrCode (*updateh)(SUNAdaptController C, sunrealtype h, sunrealtype dsm); + SUNErrCode (*space)(SUNAdaptController C, long int *lenrw, long int *leniw); }; @@ -137,7 +137,7 @@ note these requirements below. Additionally, we note the behavior of the base SU SUNAdaptController_Type id = SUNAdaptController_GetType(C); -.. c:function:: int SUNAdaptController_Destroy(SUNAdaptController C) +.. c:function:: SUNErrCode SUNAdaptController_Destroy(SUNAdaptController C) Deallocates the controller *C*. If this method is not provided by the implementation, the base class method will free both the *content* and @@ -147,8 +147,7 @@ note these requirements below. Additionally, we note the behavior of the base SU routine). :param C: the :c:type:`SUNAdaptController` object. - :return: error code indicating success failure - (see :numref:`SUNAdaptController.Description.errorCodes`). + :return: :c:type:`SUNErrCode` indicating success or failure. Usage: @@ -156,7 +155,7 @@ note these requirements below. Additionally, we note the behavior of the base SU retval = SUNAdaptController_Destroy(C); -.. c:function:: int SUNAdaptController_EstimateStep(SUNAdaptController C, sunrealtype h, int p, sunrealtype dsm, sunrealtype* hnew) +.. c:function:: SUNErrCode SUNAdaptController_EstimateStep(SUNAdaptController C, sunrealtype h, int p, sunrealtype dsm, sunrealtype* hnew) Estimates a single-rate step size. This routine is required for controllers of type ``SUN_ADAPTCONTROLLER_H``. If this is not provided by the @@ -167,8 +166,7 @@ note these requirements below. Additionally, we note the behavior of the base SU :param p: the current order of accuracy for the time integration method. :param dsm: the local temporal estimate from the previous step attempt. :param hnew: (output) the estimated step size. - :return: error code indicating success failure - (see :numref:`SUNAdaptController.Description.errorCodes`). + :return: :c:type:`SUNErrCode` indicating success or failure. Usage: @@ -176,14 +174,13 @@ note these requirements below. Additionally, we note the behavior of the base SU retval = SUNAdaptController_EstimateStep(C, hcur, p, dsm, &hnew); -.. c:function:: int SUNAdaptController_Reset(SUNAdaptController C) +.. c:function:: SUNErrCode SUNAdaptController_Reset(SUNAdaptController C) Resets the controller to its initial state, e.g., if it stores a small number of previous *dsm* or *h* values. :param C: the :c:type:`SUNAdaptController` object. - :return: error code indicating success failure - (see :numref:`SUNAdaptController.Description.errorCodes`). + :return: :c:type:`SUNErrCode` indicating success or failure. Usage: @@ -191,13 +188,12 @@ note these requirements below. Additionally, we note the behavior of the base SU retval = SUNAdaptController_Reset(C); -.. c:function:: int SUNAdaptController_SetDefaults(SUNAdaptController C) +.. c:function:: SUNErrCode SUNAdaptController_SetDefaults(SUNAdaptController C) Sets the controller parameters to their default values. :param C: the :c:type:`SUNAdaptController` object. - :return: error code indicating success failure - (see :numref:`SUNAdaptController.Description.errorCodes`). + :return: :c:type:`SUNErrCode` indicating success or failure. Usage: @@ -205,14 +201,13 @@ note these requirements below. Additionally, we note the behavior of the base SU retval = SUNAdaptController_SetDefaults(C); -.. c:function:: int SUNAdaptController_Write(SUNAdaptController C, FILE* fptr) +.. c:function:: SUNErrCode SUNAdaptController_Write(SUNAdaptController C, FILE* fptr) Writes all controller parameters to the indicated file pointer. :param C: the :c:type:`SUNAdaptController` object. :param fptr: the output stream to write the parameters to. - :return: error code indicating success failure - (see :numref:`SUNAdaptController.Description.errorCodes`). + :return: :c:type:`SUNErrCode` indicating success or failure. Usage: @@ -220,7 +215,7 @@ note these requirements below. Additionally, we note the behavior of the base SU retval = SUNAdaptController_Write(C, stdout); -.. c:function:: int SUNAdaptController_SetErrorBias(SUNAdaptController C, sunrealtype bias) +.. c:function:: SUNErrCode SUNAdaptController_SetErrorBias(SUNAdaptController C, sunrealtype bias) Sets an error bias factor for scaling the local error factors. This is typically used to slightly exaggerate the temporal error during the @@ -229,8 +224,7 @@ note these requirements below. Additionally, we note the behavior of the base SU :param C: the :c:type:`SUNAdaptController` object. :param bias: the error bias factor -- an input :math:`\leq 0` indicates to use the default value for the controller. - :return: error code indicating success failure - (see :numref:`SUNAdaptController.Description.errorCodes`). + :return: :c:type:`SUNErrCode` indicating success or failure. Usage: @@ -238,7 +232,7 @@ note these requirements below. Additionally, we note the behavior of the base SU retval = SUNAdaptController_SetErrorBias(C, 1.2); -.. c:function:: int SUNAdaptController_UpdateH(SUNAdaptController C, sunrealtype h, sunrealtype dsm) +.. c:function:: SUNErrCode SUNAdaptController_UpdateH(SUNAdaptController C, sunrealtype h, sunrealtype dsm) Notifies a controller of type SUN_ADAPTCONTROLLER_H that a successful time step was taken with stepsize *h* and local error factor *dsm*, indicating that these @@ -249,8 +243,7 @@ note these requirements below. Additionally, we note the behavior of the base SU :param C: the :c:type:`SUNAdaptController` object. :param h: the successful step size. :param dsm: the successful temporal error estimate. - :return: error code indicating success failure - (see :numref:`SUNAdaptController.Description.errorCodes`). + :return: :c:type:`SUNErrCode` indicating success or failure. Usage: @@ -258,7 +251,7 @@ note these requirements below. Additionally, we note the behavior of the base SU retval = SUNAdaptController_UpdateH(C, h, dsm); -.. c:function:: int SUNAdaptController_Space(SUNAdaptController C, long int *lenrw, long int *leniw) +.. c:function:: SUNErrCode SUNAdaptController_Space(SUNAdaptController C, long int *lenrw, long int *leniw) Informative routine that returns the memory requirements of the :c:type:`SUNAdaptController` object. @@ -269,8 +262,7 @@ note these requirements below. Additionally, we note the behavior of the base SU :param leniw: (output) number of ``sunindextype`` words stored in the controller. This may also include pointers, `int` and `long int` words. - :return: error code indicating success failure - (see :numref:`SUNAdaptController.Description.errorCodes`). + :return: :c:type:`SUNErrCode` indicating success or failure. Usage: @@ -280,30 +272,6 @@ note these requirements below. Additionally, we note the behavior of the base SU -.. _SUNAdaptController.Description.errorCodes: - -SUNAdaptController Error Codes ------------------------------- - -SUNAdaptController functions return one of the following set of error codes: - -* ``SUNADAPTCONTROLLER_SUCCESS`` (0) -- successful call. - -* ``SUNADAPTCONTROLLER_ILL_INPUT`` (-1001) -- an illegal input has been provided to the function. - -* ``SUNADAPTCONTROLLER_MEM_FAIL`` (-1002) -- a memory access or allocation failed. - -* ``SUNADAPTCONTROLLER_USER_FCN_FAIL`` (-1003) -- a user-supplied function returned a nonzero [error] value. - -* ``SUNADAPTCONTROLLER_OPERATION_FAIL`` (-1004) -- catch-all for errors not in the above list. - -.. note:: - The SUNDIALS time integrators do not rely on these specific return values and only - on whether the returned values are 0 (successful) or non-zero (failure). Thus, - user-defined implementations are not required to use these specific error codes, - so long as the zero/non-zero convention is followed. - - C/C++ API Usage --------------- diff --git a/doc/shared/sunadaptcontroller/SUNAdaptController_ImExGus.rst b/doc/shared/sunadaptcontroller/SUNAdaptController_ImExGus.rst index c0a54fddf8..2a052c566d 100644 --- a/doc/shared/sunadaptcontroller/SUNAdaptController_ImExGus.rst +++ b/doc/shared/sunadaptcontroller/SUNAdaptController_ImExGus.rst @@ -108,7 +108,7 @@ routines: SUNAdaptController C = SUNAdaptController_ImExGus(sunctx); -.. c:function:: int SUNAdaptController_SetParams_ImExGus(SUNAdaptController C, sunrealtype k1e, sunrealtype k2e, sunrealtype k1i, sunrealtype k2i) +.. c:function:: SUNErrCode SUNAdaptController_SetParams_ImExGus(SUNAdaptController C, sunrealtype k1e, sunrealtype k2e, sunrealtype k1i, sunrealtype k2i) This user-callable function provides control over the relevant parameters above. This should be called *before* the time integrator is called to evolve @@ -119,7 +119,7 @@ routines: :param k2e: parameter used within the controller time step estimate. :param k1i: parameter used within the controller time step estimate. :param k2i: parameter used within the controller time step estimate. - :return: error code indication success or failure (see :numref:`SUNAdaptController.Description.errorCodes`). + :return: :c:type:`SUNErrCode` indicating success or failure. Usage: diff --git a/doc/shared/sunadaptcontroller/SUNAdaptController_Soderlind.rst b/doc/shared/sunadaptcontroller/SUNAdaptController_Soderlind.rst index e7bf4867f2..4a4ed4ad89 100644 --- a/doc/shared/sunadaptcontroller/SUNAdaptController_Soderlind.rst +++ b/doc/shared/sunadaptcontroller/SUNAdaptController_Soderlind.rst @@ -99,7 +99,7 @@ also provides the following additional user-callable routines: SUNAdaptController C = SUNAdaptController_Soderlind(sunctx); -.. c:function:: int SUNAdaptController_SetParams_Soderlind(SUNAdaptController C, sunrealtype k1, sunrealtype k2, sunrealtype k3, sunrealtype k4, sunrealtype k5) +.. c:function:: SUNErrCode SUNAdaptController_SetParams_Soderlind(SUNAdaptController C, sunrealtype k1, sunrealtype k2, sunrealtype k3, sunrealtype k4, sunrealtype k5) This user-callable function provides control over the relevant parameters above. This should be called *before* the time integrator is called to evolve @@ -111,7 +111,7 @@ also provides the following additional user-callable routines: :param k3: parameter used within the controller time step estimate. :param k4: parameter used within the controller time step estimate. :param k5: parameter used within the controller time step estimate. - :return: error code indication success or failure (see :numref:`SUNAdaptController.Description.errorCodes`). + :return: :c:type:`SUNErrCode` indicating success or failure. Usage: @@ -137,7 +137,7 @@ also provides the following additional user-callable routines: SUNAdaptController C = SUNAdaptController_PID(sunctx); -.. c:function:: int SUNAdaptController_SetParams_PID(SUNAdaptController C, sunrealtype k1, sunrealtype k2, sunrealtype k3) +.. c:function:: SUNErrCode SUNAdaptController_SetParams_PID(SUNAdaptController C, sunrealtype k1, sunrealtype k2, sunrealtype k3) This user-callable function provides control over the relevant parameters above for a PID controller, setting :math:`k_4 = k_5 = 0`. This should be @@ -147,7 +147,7 @@ also provides the following additional user-callable routines: :param k1: parameter used within the controller time step estimate. :param k2: parameter used within the controller time step estimate. :param k3: parameter used within the controller time step estimate. - :return: error code indication success or failure (see :numref:`SUNAdaptController.Description.errorCodes`). + :return: :c:type:`SUNErrCode` indicating success or failure. Usage: @@ -172,7 +172,7 @@ also provides the following additional user-callable routines: SUNAdaptController C = SUNAdaptController_PI(sunctx); -.. c:function:: int SUNAdaptController_SetParams_PI(SUNAdaptController C, sunrealtype k1, sunrealtype k2) +.. c:function:: SUNErrCode SUNAdaptController_SetParams_PI(SUNAdaptController C, sunrealtype k1, sunrealtype k2) This user-callable function provides control over the relevant parameters above for a PI controller, setting :math:`k_3 = k_4 = k_5 = 0`. This should @@ -181,7 +181,7 @@ also provides the following additional user-callable routines: :param C: the SUNAdaptController_Soderlind object. :param k1: parameter used within the controller time step estimate. :param k2: parameter used within the controller time step estimate. - :return: error code indication success or failure (see :numref:`SUNAdaptController.Description.errorCodes`). + :return: :c:type:`SUNErrCode` indicating success or failure. Usage: @@ -206,7 +206,7 @@ also provides the following additional user-callable routines: SUNAdaptController C = SUNAdaptController_I(sunctx); -.. c:function:: int SUNAdaptController_SetParams_I(SUNAdaptController C, sunrealtype k1) +.. c:function:: SUNErrCode SUNAdaptController_SetParams_I(SUNAdaptController C, sunrealtype k1) This user-callable function provides control over the relevant parameters above for an I controller, setting :math:`k_2 = k_3 = k_4 = k_5 = 0`. This @@ -214,7 +214,7 @@ also provides the following additional user-callable routines: :param C: the SUNAdaptController_Soderlind object. :param k1: parameter used within the controller time step estimate. - :return: error code indication success or failure (see :numref:`SUNAdaptController.Description.errorCodes`). + :return: :c:type:`SUNErrCode` indicating success or failure. Usage: @@ -240,7 +240,7 @@ also provides the following additional user-callable routines: SUNAdaptController C = SUNAdaptController_ExpGus(sunctx); -.. c:function:: int SUNAdaptController_SetParams_ExpGus(SUNAdaptController C, sunrealtype k1_hat, sunrealtype k2_hat) +.. c:function:: SUNErrCode SUNAdaptController_SetParams_ExpGus(SUNAdaptController C, sunrealtype k1_hat, sunrealtype k2_hat) This user-callable function provides control over the relevant parameters above for the explicit Gustafsson controller, setting :math:`k_3 = k_4 = k_5 = 0`. @@ -260,7 +260,7 @@ also provides the following additional user-callable routines: :param C: the SUNAdaptController_Soderlind object. :param k1_hat: parameter used within the explicit Gustafsson controller time step estimate. :param k2_hat: parameter used within the explicit Gustafsson controller time step estimate. - :return: error code indication success or failure (see :numref:`SUNAdaptController.Description.errorCodes`). + :return: :c:type:`SUNErrCode` indicating success or failure. Usage: @@ -286,7 +286,7 @@ also provides the following additional user-callable routines: SUNAdaptController C = SUNAdaptController_ImpGus(sunctx); -.. c:function:: int SUNAdaptController_SetParams_ImpGus(SUNAdaptController C, sunrealtype k1_hat, sunrealtype k2_hat) +.. c:function:: SUNErrCode SUNAdaptController_SetParams_ImpGus(SUNAdaptController C, sunrealtype k1_hat, sunrealtype k2_hat) This user-callable function provides control over the relevant parameters above for the implicit Gustafsson controller, setting :math:`k_3 = k_4 = k_5 = 0`. @@ -306,7 +306,7 @@ also provides the following additional user-callable routines: :param C: the SUNAdaptController_Soderlind object. :param k1_hat: parameter used within the implicit Gustafsson controller time step estimate. :param k2_hat: parameter used within the implicit Gustafsson controller time step estimate. - :return: error code indication success or failure (see :numref:`SUNAdaptController.Description.errorCodes`). + :return: :c:type:`SUNErrCode` indicating success or failure. Usage: diff --git a/doc/shared/sunmemory/SUNMemory_CUDA.rst b/doc/shared/sunmemory/SUNMemory_CUDA.rst index cf42c1ab98..1f2cb99495 100644 --- a/doc/shared/sunmemory/SUNMemory_CUDA.rst +++ b/doc/shared/sunmemory/SUNMemory_CUDA.rst @@ -68,10 +68,10 @@ The implementation provides the following operations defined by the **Returns:** - * An ``int`` flag indicating success (zero) or failure (non-zero). + * A new :c:type:`SUNMemory` object. -.. c:function:: int SUNMemoryHelper_Dealloc_Cuda(SUNMemoryHelper helper, \ +.. c:function:: SUNErrCode SUNMemoryHelper_Dealloc_Cuda(SUNMemoryHelper helper, \ SUNMemory mem, void* queue) Deallocates the ``mem->ptr`` field if it is owned by ``mem``, and then @@ -85,10 +85,10 @@ The implementation provides the following operations defined by the **Returns:** - * An ``int`` flag indicating success (zero) or failure (non-zero). + * A :c:type:`SUNErrCode` indicating success or failure. -.. c:function:: int SUNMemoryHelper_Copy_Cuda(SUNMemoryHelper helper, \ +.. c:function:: SUNErrCode SUNMemoryHelper_Copy_Cuda(SUNMemoryHelper helper, \ SUNMemory dst, SUNMemory src, \ size_t mem_size, void* queue) @@ -108,10 +108,10 @@ The implementation provides the following operations defined by the **Returns:** - * An ``int`` flag indicating success (zero) or failure (non-zero). + * A :c:type:`SUNErrCode` indicating success or failure. -.. c:function:: int SUNMemoryHelper_CopyAsync_Cuda(SUNMemoryHelper helper, \ +.. c:function:: SUNErrCode SUNMemoryHelper_CopyAsync_Cuda(SUNMemoryHelper helper, \ SUNMemory dst, \ SUNMemory src, \ size_t mem_size, void* queue) @@ -133,10 +133,10 @@ The implementation provides the following operations defined by the **Returns:** - * An ``int`` flag indicating success (zero) or failure (non-zero). + * A :c:type:`SUNErrCode` indicating success or failure. -.. c:function:: int SUNMemoryHelper_GetAllocStats_Cuda(SUNMemoryHelper helper, SUNMemoryType mem_type, unsigned long* num_allocations, \ +.. c:function:: SUNErrCode SUNMemoryHelper_GetAllocStats_Cuda(SUNMemoryHelper helper, SUNMemoryType mem_type, unsigned long* num_allocations, \ unsigned long* num_deallocations, size_t* bytes_allocated, \ size_t* bytes_high_watermark) @@ -153,4 +153,4 @@ The implementation provides the following operations defined by the **Returns:** - * An ``int`` flag indicating success (zero) or failure (non-zero). + * A :c:type:`SUNErrCode` indicating success or failure. diff --git a/doc/shared/sunmemory/SUNMemory_Description.rst b/doc/shared/sunmemory/SUNMemory_Description.rst index bb66520559..55b3acd552 100644 --- a/doc/shared/sunmemory/SUNMemory_Description.rst +++ b/doc/shared/sunmemory/SUNMemory_Description.rst @@ -97,21 +97,20 @@ This API consists of three new SUNDIALS types: :c:type:`SUNMemoryType`, struct SUNMemoryHelper_Ops_ { /* operations that implementations are required to provide */ - int (*alloc)(SUNMemoryHelper, SUNMemory* memptr size_t mem_size, + SUNErrCode (*alloc)(SUNMemoryHelper, SUNMemory* memptr size_t mem_size, SUNMemoryType mem_type, void* queue); - int (*dealloc)(SUNMemoryHelper, SUNMemory mem, void* queue); - int (*copy)(SUNMemoryHelper, SUNMemory dst, SUNMemory src, + SUNErrCode (*dealloc)(SUNMemoryHelper, SUNMemory mem, void* queue); + SUNErrCode (*copy)(SUNMemoryHelper, SUNMemory dst, SUNMemory src, size_t mem_size, void* queue); /* operations that provide default implementations */ - int (*copyasync)(SUNMemoryHelper, SUNMemory dst, - SUNMemory src, size_t mem_size, - void* queue); - int (*getallocstats)(SUNMemoryHelper, SUNMemoryType mem_type, unsigned long* num_allocations, - unsigned long* num_deallocations, size_t* bytes_allocated, - size_t* bytes_high_watermark); + SUNErrCode (*copyasync)(SUNMemoryHelper, SUNMemory dst, + SUNMemory src, size_t mem_size, void* queue); + SUNErrCode (*getallocstats)(SUNMemoryHelper, SUNMemoryType mem_type, unsigned long* num_allocations, + unsigned long* num_deallocations, size_t* bytes_allocated, + size_t* bytes_high_watermark); SUNMemoryHelper (*clone)(SUNMemoryHelper); - int (*destroy)(SUNMemoryHelper); + SUNErrCode (*destroy)(SUNMemoryHelper); }; @@ -146,10 +145,10 @@ must define: **Returns:** - * An ``int`` flag indicating success (zero) or failure (non-zero). + * A new :c:type:`SUNMemory` object. -.. c:function:: int SUNMemoryHelper_Dealloc(SUNMemoryHelper helper, \ +.. c:function:: SUNErrCode SUNMemoryHelper_Dealloc(SUNMemoryHelper helper, \ SUNMemory mem, void* queue) Deallocates the ``mem->ptr`` field if it is owned by ``mem``, and then @@ -165,10 +164,10 @@ must define: **Returns:** - * An ``int`` flag indicating success (zero) or failure (non-zero). + * A :c:type:`SUNErrCode` indicating success or failure. -.. c:function:: int SUNMemoryHelper_Copy(SUNMemoryHelper helper, \ +.. c:function:: SUNErrCode SUNMemoryHelper_Copy(SUNMemoryHelper helper, \ SUNMemory dst, SUNMemory src, \ size_t mem_size, void* queue) @@ -190,7 +189,7 @@ must define: **Returns:** - * An ``int`` flag indicating success (zero) or failure (non-zero). + * A :c:type:`SUNErrCode` indicating success or failure. @@ -263,7 +262,7 @@ require a SUNMemoryHelper instance: The ``SUNMemoryHelper`` argument was added to the function signature. -.. c:function:: int SUNMemoryHelper_CopyOps(SUNMemoryHelper src, \ +.. c:function:: SUNErrCode SUNMemoryHelper_CopyOps(SUNMemoryHelper src, \ SUNMemoryHelper dst) Copies the ``ops`` field of ``src`` to the ``ops`` field of ``dst``. @@ -276,10 +275,10 @@ require a SUNMemoryHelper instance: **Returns:** - * An ``int`` flag indicating success (zero) or failure (non-zero). + * A :c:type:`SUNErrCode` indicating success or failure. -.. c:function:: int SUNMemoryHelper_GetAllocStats(SUNMemoryHelper helper, SUNMemoryType mem_type, unsigned long* num_allocations, \ +.. c:function:: SUNErrCode SUNMemoryHelper_GetAllocStats(SUNMemoryHelper helper, SUNMemoryType mem_type, unsigned long* num_allocations, \ unsigned long* num_deallocations, size_t* bytes_allocated, \ size_t* bytes_high_watermark) @@ -296,7 +295,7 @@ require a SUNMemoryHelper instance: **Returns:** - * An ``int`` flag indicating success (zero) or failure (non-zero). + * A :c:type:`SUNErrCode` indicating success or failure. .. _SUNMemory.Description.Overridable: @@ -308,7 +307,7 @@ In addition, the SUNMemoryHelper API defines the following *optionally overridable* operations which an implementation may define: -.. c:function:: int SUNMemoryHelper_CopyAsync(SUNMemoryHelper helper, \ +.. c:function:: SUNErrCode SUNMemoryHelper_CopyAsync(SUNMemoryHelper helper, \ SUNMemory dst, SUNMemory src, \ size_t mem_size, void* queue) @@ -359,7 +358,7 @@ overridable* operations which an implementation may define: ``helper->ops``, and not the ``helper->content`` field. -.. c:function:: int SUNMemoryHelper_Destroy(SUNMemoryHelper helper) +.. c:function:: SUNErrCode SUNMemoryHelper_Destroy(SUNMemoryHelper helper) Destroys (frees) the ``SUNMemoryHelper`` object itself. @@ -369,7 +368,7 @@ overridable* operations which an implementation may define: **Returns:** - * An ``int`` flag indicating success (zero) or failure (non-zero). + * A :c:type:`SUNErrCode` indicating success or failure. .. note:: diff --git a/doc/shared/sunmemory/SUNMemory_HIP.rst b/doc/shared/sunmemory/SUNMemory_HIP.rst index 18598b75c8..4fbd21103f 100644 --- a/doc/shared/sunmemory/SUNMemory_HIP.rst +++ b/doc/shared/sunmemory/SUNMemory_HIP.rst @@ -71,7 +71,7 @@ The implementation provides the following operations defined by the * An ``int`` flag indicating success (zero) or failure (non-zero). -.. c:function:: int SUNMemoryHelper_Dealloc_Hip(SUNMemoryHelper helper, \ +.. c:function:: SUNErrCode SUNMemoryHelper_Dealloc_Hip(SUNMemoryHelper helper, \ SUNMemory mem, \ void* queue) @@ -88,7 +88,7 @@ The implementation provides the following operations defined by the * An ``int`` flag indicating success (zero) or failure (non-zero). -.. c:function:: int SUNMemoryHelper_Copy_Hip(SUNMemoryHelper helper, \ +.. c:function:: SUNErrCode SUNMemoryHelper_Copy_Hip(SUNMemoryHelper helper, \ SUNMemory dst, SUNMemory src, \ size_t mem_size, void* queue) @@ -110,7 +110,7 @@ The implementation provides the following operations defined by the * An ``int`` flag indicating success (zero) or failure (non-zero). -.. c:function:: int SUNMemoryHelper_CopyAsync_Hip(SUNMemoryHelper helper, \ +.. c:function:: SUNErrCode SUNMemoryHelper_CopyAsync_Hip(SUNMemoryHelper helper, \ SUNMemory dst, \ SUNMemory src, \ size_t mem_size, void* queue) @@ -135,7 +135,7 @@ The implementation provides the following operations defined by the * An ``int`` flag indicating success (zero) or failure (non-zero). -.. c:function:: int SUNMemoryHelper_GetAllocStats_Hip(SUNMemoryHelper helper, SUNMemoryType mem_type, unsigned long* num_allocations, \ +.. c:function:: SUNErrCode SUNMemoryHelper_GetAllocStats_Hip(SUNMemoryHelper helper, SUNMemoryType mem_type, unsigned long* num_allocations, \ unsigned long* num_deallocations, size_t* bytes_allocated, \ size_t* bytes_high_watermark) diff --git a/doc/shared/sunmemory/SUNMemory_SYCL.rst b/doc/shared/sunmemory/SUNMemory_SYCL.rst index a90189f84d..f009ce9c6a 100644 --- a/doc/shared/sunmemory/SUNMemory_SYCL.rst +++ b/doc/shared/sunmemory/SUNMemory_SYCL.rst @@ -66,10 +66,10 @@ The implementation provides the following operations defined by the **Returns:** - * An ``int`` flag indicating success (zero) or failure (non-zero). + * A new :c:type:`SUNMemory` object. -.. c:function:: int SUNMemoryHelper_Dealloc_Sycl(SUNMemoryHelper helper, \ +.. c:function:: SUNErrCode SUNMemoryHelper_Dealloc_Sycl(SUNMemoryHelper helper, \ SUNMemory mem, void* queue) Deallocates the ``mem->ptr`` field if it is owned by ``mem``, and then @@ -84,10 +84,10 @@ The implementation provides the following operations defined by the **Returns:** - * An ``int`` flag indicating success (zero) or failure (non-zero). + * A :c:type:`SUNErrCode` indicating success or failure. -.. c:function:: int SUNMemoryHelper_Copy_Sycl(SUNMemoryHelper helper, \ +.. c:function:: SUNErrCode SUNMemoryHelper_Copy_Sycl(SUNMemoryHelper helper, \ SUNMemory dst, SUNMemory src, \ size_t mem_size, void* queue) @@ -108,10 +108,10 @@ The implementation provides the following operations defined by the **Returns:** - * An ``int`` flag indicating success (zero) or failure (non-zero). + * A :c:type:`SUNErrCode` indicating success or failure. -.. c:function:: int SUNMemoryHelper_CopyAsync_Sycl(SUNMemoryHelper helper, \ +.. c:function:: SUNErrCode SUNMemoryHelper_CopyAsync_Sycl(SUNMemoryHelper helper, \ SUNMemory dst, \ SUNMemory src, \ size_t mem_size, void* queue) @@ -133,10 +133,10 @@ The implementation provides the following operations defined by the **Returns:** - * An ``int`` flag indicating success (zero) or failure (non-zero). + * A :c:type:`SUNErrCode` indicating success or failure. -.. c:function:: int SUNMemoryHelper_GetAllocStats_Sycl(SUNMemoryHelper helper, SUNMemoryType mem_type, unsigned long* num_allocations, \ +.. c:function:: SUNErrCode SUNMemoryHelper_GetAllocStats_Sycl(SUNMemoryHelper helper, SUNMemoryType mem_type, unsigned long* num_allocations, \ unsigned long* num_deallocations, size_t* bytes_allocated, \ size_t* bytes_high_watermark) @@ -153,4 +153,4 @@ The implementation provides the following operations defined by the **Returns:** - * An ``int`` flag indicating success (zero) or failure (non-zero). + * A :c:type:`SUNErrCode` indicating success or failure. diff --git a/include/sunadaptcontroller/sunadaptcontroller_imexgus.h b/include/sunadaptcontroller/sunadaptcontroller_imexgus.h index a6db46d896..e15f93bc21 100644 --- a/include/sunadaptcontroller/sunadaptcontroller_imexgus.h +++ b/include/sunadaptcontroller/sunadaptcontroller_imexgus.h @@ -48,31 +48,38 @@ typedef struct _SUNAdaptControllerContent_ImExGus* SUNAdaptControllerContent_ImE SUNDIALS_EXPORT SUNAdaptController SUNAdaptController_ImExGus(SUNContext sunctx); + SUNDIALS_EXPORT -int SUNAdaptController_SetParams_ImExGus(SUNAdaptController C, sunrealtype k1e, - sunrealtype k2e, sunrealtype k1i, - sunrealtype k2i); +SUNErrCode SUNAdaptController_SetParams_ImExGus(SUNAdaptController C, + sunrealtype k1e, sunrealtype k2e, + sunrealtype k1i, sunrealtype k2i); SUNDIALS_EXPORT SUNAdaptController_Type SUNAdaptController_GetType_ImExGus(SUNAdaptController C); + SUNDIALS_EXPORT -int SUNAdaptController_EstimateStep_ImExGus(SUNAdaptController C, sunrealtype h, - int p, sunrealtype dsm, - sunrealtype* hnew); +SUNErrCode SUNAdaptController_EstimateStep_ImExGus(SUNAdaptController C, + sunrealtype h, int p, + sunrealtype dsm, + sunrealtype* hnew); SUNDIALS_EXPORT -int SUNAdaptController_Reset_ImExGus(SUNAdaptController C); +SUNErrCode SUNAdaptController_Reset_ImExGus(SUNAdaptController C); + SUNDIALS_EXPORT -int SUNAdaptController_SetDefaults_ImExGus(SUNAdaptController C); +SUNErrCode SUNAdaptController_SetDefaults_ImExGus(SUNAdaptController C); + SUNDIALS_EXPORT -int SUNAdaptController_Write_ImExGus(SUNAdaptController C, FILE* fptr); +SUNErrCode SUNAdaptController_Write_ImExGus(SUNAdaptController C, FILE* fptr); + SUNDIALS_EXPORT -int SUNAdaptController_SetErrorBias_ImExGus(SUNAdaptController C, - sunrealtype bias); +SUNErrCode SUNAdaptController_SetErrorBias_ImExGus(SUNAdaptController C, + sunrealtype bias); SUNDIALS_EXPORT -int SUNAdaptController_UpdateH_ImExGus(SUNAdaptController C, sunrealtype h, - sunrealtype dsm); +SUNErrCode SUNAdaptController_UpdateH_ImExGus(SUNAdaptController C, + sunrealtype h, sunrealtype dsm); + SUNDIALS_EXPORT -int SUNAdaptController_Space_ImExGus(SUNAdaptController C, long int* lenrw, - long int* leniw); +SUNErrCode SUNAdaptController_Space_ImExGus(SUNAdaptController C, + long int* lenrw, long int* leniw); #ifdef __cplusplus } diff --git a/include/sunadaptcontroller/sunadaptcontroller_soderlind.h b/include/sunadaptcontroller/sunadaptcontroller_soderlind.h index 3dbd20cd13..4aa1ddc694 100644 --- a/include/sunadaptcontroller/sunadaptcontroller_soderlind.h +++ b/include/sunadaptcontroller/sunadaptcontroller_soderlind.h @@ -52,59 +52,78 @@ typedef struct _SUNAdaptControllerContent_Soderlind* SUNAdaptControllerContent_S SUNDIALS_EXPORT SUNAdaptController SUNAdaptController_Soderlind(SUNContext sunctx); + SUNDIALS_EXPORT -int SUNAdaptController_SetParams_Soderlind(SUNAdaptController C, sunrealtype k1, - sunrealtype k2, sunrealtype k3, - sunrealtype k4, sunrealtype k5); +SUNErrCode SUNAdaptController_SetParams_Soderlind(SUNAdaptController C, + sunrealtype k1, sunrealtype k2, + sunrealtype k3, sunrealtype k4, + sunrealtype k5); + SUNDIALS_EXPORT SUNAdaptController_Type SUNAdaptController_GetType_Soderlind(SUNAdaptController C); + SUNDIALS_EXPORT -int SUNAdaptController_EstimateStep_Soderlind(SUNAdaptController C, - sunrealtype h, int p, - sunrealtype dsm, sunrealtype* hnew); +SUNErrCode SUNAdaptController_EstimateStep_Soderlind(SUNAdaptController C, + sunrealtype h, int p, + sunrealtype dsm, + sunrealtype* hnew); + SUNDIALS_EXPORT -int SUNAdaptController_Reset_Soderlind(SUNAdaptController C); +SUNErrCode SUNAdaptController_Reset_Soderlind(SUNAdaptController C); + SUNDIALS_EXPORT -int SUNAdaptController_SetDefaults_Soderlind(SUNAdaptController C); +SUNErrCode SUNAdaptController_SetDefaults_Soderlind(SUNAdaptController C); + SUNDIALS_EXPORT -int SUNAdaptController_Write_Soderlind(SUNAdaptController C, FILE* fptr); +SUNErrCode SUNAdaptController_Write_Soderlind(SUNAdaptController C, FILE* fptr); + SUNDIALS_EXPORT -int SUNAdaptController_SetErrorBias_Soderlind(SUNAdaptController C, - sunrealtype bias); +SUNErrCode SUNAdaptController_SetErrorBias_Soderlind(SUNAdaptController C, + sunrealtype bias); + SUNDIALS_EXPORT -int SUNAdaptController_UpdateH_Soderlind(SUNAdaptController C, sunrealtype h, - sunrealtype dsm); +SUNErrCode SUNAdaptController_UpdateH_Soderlind(SUNAdaptController C, + sunrealtype h, sunrealtype dsm); + SUNDIALS_EXPORT -int SUNAdaptController_Space_Soderlind(SUNAdaptController C, long int* lenrw, - long int* leniw); +SUNErrCode SUNAdaptController_Space_Soderlind(SUNAdaptController C, + long int* lenrw, long int* leniw); /* Convenience routines to construct subsidiary controllers */ + SUNDIALS_EXPORT SUNAdaptController SUNAdaptController_PID(SUNContext sunctx); + SUNDIALS_EXPORT -int SUNAdaptController_SetParams_PID(SUNAdaptController C, sunrealtype k1, - sunrealtype k2, sunrealtype k3); +SUNErrCode SUNAdaptController_SetParams_PID(SUNAdaptController C, sunrealtype k1, + sunrealtype k2, sunrealtype k3); + SUNDIALS_EXPORT SUNAdaptController SUNAdaptController_PI(SUNContext sunctx); + SUNDIALS_EXPORT -int SUNAdaptController_SetParams_PI(SUNAdaptController C, sunrealtype k1, - sunrealtype k2); +SUNErrCode SUNAdaptController_SetParams_PI(SUNAdaptController C, sunrealtype k1, + sunrealtype k2); + SUNDIALS_EXPORT SUNAdaptController SUNAdaptController_I(SUNContext sunctx); + SUNDIALS_EXPORT -int SUNAdaptController_SetParams_I(SUNAdaptController C, sunrealtype k1); +SUNErrCode SUNAdaptController_SetParams_I(SUNAdaptController C, sunrealtype k1); SUNDIALS_EXPORT SUNAdaptController SUNAdaptController_ExpGus(SUNContext sunctx); + SUNDIALS_EXPORT -int SUNAdaptController_SetParams_ExpGus(SUNAdaptController C, sunrealtype k1, - sunrealtype k2); +SUNErrCode SUNAdaptController_SetParams_ExpGus(SUNAdaptController C, + sunrealtype k1, sunrealtype k2); SUNDIALS_EXPORT SUNAdaptController SUNAdaptController_ImpGus(SUNContext sunctx); + SUNDIALS_EXPORT -int SUNAdaptController_SetParams_ImpGus(SUNAdaptController C, sunrealtype k1, - sunrealtype k2); +SUNErrCode SUNAdaptController_SetParams_ImpGus(SUNAdaptController C, + sunrealtype k1, sunrealtype k2); #ifdef __cplusplus } diff --git a/include/sundials/sundials_adaptcontroller.h b/include/sundials/sundials_adaptcontroller.h index 2656274041..1d71d08f64 100644 --- a/include/sundials/sundials_adaptcontroller.h +++ b/include/sundials/sundials_adaptcontroller.h @@ -97,7 +97,7 @@ SUNAdaptController_Type SUNAdaptController_GetType(SUNAdaptController C); /* Function to deallocate a SUNAdaptController object. - Any return value other than SUNADAPTCONTROLLER_SUCCESS will be treated as + Any return value other than SUN_SUCCESS will be treated as an unrecoverable failure. */ SUNDIALS_EXPORT SUNErrCode SUNAdaptController_Destroy(SUNAdaptController C); @@ -107,7 +107,7 @@ SUNErrCode SUNAdaptController_Destroy(SUNAdaptController C); controller should estimate 'hnew' so that the ensuing step will have 'dsm' value JUST BELOW 1. - Any return value other than SUNADAPTCONTROLLER_SUCCESS will be treated as + Any return value other than SUN_SUCCESS will be treated as an unrecoverable failure. */ SUNDIALS_EXPORT SUNErrCode SUNAdaptController_EstimateStep(SUNAdaptController C, sunrealtype h, @@ -146,15 +146,6 @@ SUNDIALS_EXPORT SUNErrCode SUNAdaptController_Space(SUNAdaptController C, long int* lenrw, long int* leniw); -/* ----------------------------------------------------------------- - * SUNAdaptController error codes - * ----------------------------------------------------------------- */ - -/* TODO(CJB): eliminate these after updating soderlind and imexgus in follow-on PR */ -#define SUNADAPTCONTROLLER_SUCCESS 0 /* function successfull */ -#define SUNADAPTCONTROLLER_ILL_INPUT -1001 /* illegal function input */ -#define SUNADAPTCONTROLLER_USER_FCN_FAIL -1003 /* user-supplied fcn failure */ - #ifdef __cplusplus } #endif diff --git a/include/sundials/sundials_errors.h b/include/sundials/sundials_errors.h index ae491a9577..690cfc4ac9 100644 --- a/include/sundials/sundials_errors.h +++ b/include/sundials/sundials_errors.h @@ -36,12 +36,15 @@ ENTRY(SUN_ERR_ARG_DIMSMISMATCH, "argument dimensions do not agree") \ \ ENTRY(SUN_ERR_CORRUPT, "Object is NULL or corrupt") \ + ENTRY(SUN_ERR_OUTOFRANGE, "Value is out of the expected range") \ ENTRY(SUN_ERR_FILE_OPEN, "Unable to open file") \ ENTRY(SUN_ERR_MEM_FAIL, "a memory operation failed") \ ENTRY(SUN_ERR_MALLOC_FAIL, "malloc returned NULL") \ + ENTRY(SUN_ERR_EXT_FAIL, "a failure occurred in an external library") \ ENTRY(SUN_ERR_DESTROY_FAIL, "a destroy function returned an error") \ ENTRY(SUN_ERR_NOT_IMPLEMENTED, \ "operation is not implemented: function pointer is NULL") \ + ENTRY(SUN_ERR_USER_FCN_FAIL, "the user provided callback function failed") \ \ ENTRY(SUN_ERR_PROFILER_MAPFULL, \ "the number of profiler entries exceeded SUNPROFILER_MAX_ENTRIES") \ diff --git a/include/sunmemory/sunmemory_cuda.h b/include/sunmemory/sunmemory_cuda.h index 4641066851..288dbb8b8a 100644 --- a/include/sunmemory/sunmemory_cuda.h +++ b/include/sunmemory/sunmemory_cuda.h @@ -32,36 +32,37 @@ SUNMemoryHelper SUNMemoryHelper_Cuda(SUNContext sunctx); /* SUNMemoryHelper functions */ SUNDIALS_EXPORT -int SUNMemoryHelper_Alloc_Cuda(SUNMemoryHelper helper, SUNMemory* memptr, - size_t mem_size, SUNMemoryType mem_type, - void* queue); +SUNErrCode SUNMemoryHelper_Alloc_Cuda(SUNMemoryHelper helper, SUNMemory* memptr, + size_t mem_size, SUNMemoryType mem_type, + void* queue); SUNDIALS_EXPORT SUNMemoryHelper SUNMemoryHelper_Clone_Cuda(SUNMemoryHelper helper); SUNDIALS_EXPORT -int SUNMemoryHelper_Dealloc_Cuda(SUNMemoryHelper helper, SUNMemory mem, - void* queue); +SUNErrCode SUNMemoryHelper_Dealloc_Cuda(SUNMemoryHelper helper, SUNMemory mem, + void* queue); SUNDIALS_EXPORT -int SUNMemoryHelper_Copy_Cuda(SUNMemoryHelper helper, SUNMemory dst, - SUNMemory src, size_t memory_size, void* queue); +SUNErrCode SUNMemoryHelper_Copy_Cuda(SUNMemoryHelper helper, SUNMemory dst, + SUNMemory src, size_t memory_size, + void* queue); SUNDIALS_EXPORT -int SUNMemoryHelper_CopyAsync_Cuda(SUNMemoryHelper helper, SUNMemory dst, - SUNMemory src, size_t memory_size, - void* queue); +SUNErrCode SUNMemoryHelper_CopyAsync_Cuda(SUNMemoryHelper helper, SUNMemory dst, + SUNMemory src, size_t memory_size, + void* queue); SUNDIALS_EXPORT -int SUNMemoryHelper_Destroy_Cuda(SUNMemoryHelper helper); +SUNErrCode SUNMemoryHelper_Destroy_Cuda(SUNMemoryHelper helper); SUNDIALS_EXPORT -int SUNMemoryHelper_GetAllocStats_Cuda(SUNMemoryHelper helper, - SUNMemoryType mem_type, - unsigned long* num_allocations, - unsigned long* num_deallocations, - size_t* bytes_allocated, - size_t* bytes_high_watermark); +SUNErrCode SUNMemoryHelper_GetAllocStats_Cuda(SUNMemoryHelper helper, + SUNMemoryType mem_type, + unsigned long* num_allocations, + unsigned long* num_deallocations, + size_t* bytes_allocated, + size_t* bytes_high_watermark); #ifdef __cplusplus } diff --git a/include/sunmemory/sunmemory_hip.h b/include/sunmemory/sunmemory_hip.h index 05603bddae..c3a5bb609e 100644 --- a/include/sunmemory/sunmemory_hip.h +++ b/include/sunmemory/sunmemory_hip.h @@ -32,35 +32,37 @@ SUNMemoryHelper SUNMemoryHelper_Hip(SUNContext sunctx); /* SUNMemoryHelper functions */ SUNDIALS_EXPORT -int SUNMemoryHelper_Alloc_Hip(SUNMemoryHelper helper, SUNMemory* memptr, - size_t mem_size, SUNMemoryType mem_type, - void* queue); +SUNErrCode SUNMemoryHelper_Alloc_Hip(SUNMemoryHelper helper, SUNMemory* memptr, + size_t mem_size, SUNMemoryType mem_type, + void* queue); SUNDIALS_EXPORT SUNMemoryHelper SUNMemoryHelper_Clone_Hip(SUNMemoryHelper helper); SUNDIALS_EXPORT -int SUNMemoryHelper_Dealloc_Hip(SUNMemoryHelper helper, SUNMemory mem, - void* queue); +SUNErrCode SUNMemoryHelper_Dealloc_Hip(SUNMemoryHelper helper, SUNMemory mem, + void* queue); SUNDIALS_EXPORT -int SUNMemoryHelper_Copy_Hip(SUNMemoryHelper helper, SUNMemory dst, - SUNMemory src, size_t memory_size, void* queue); +SUNErrCode SUNMemoryHelper_Copy_Hip(SUNMemoryHelper helper, SUNMemory dst, + SUNMemory src, size_t memory_size, + void* queue); SUNDIALS_EXPORT -int SUNMemoryHelper_CopyAsync_Hip(SUNMemoryHelper helper, SUNMemory dst, - SUNMemory src, size_t memory_size, void* queue); +SUNErrCode SUNMemoryHelper_CopyAsync_Hip(SUNMemoryHelper helper, SUNMemory dst, + SUNMemory src, size_t memory_size, + void* queue); SUNDIALS_EXPORT -int SUNMemoryHelper_Destroy_Hip(SUNMemoryHelper helper); +SUNErrCode SUNMemoryHelper_Destroy_Hip(SUNMemoryHelper helper); SUNDIALS_EXPORT -int SUNMemoryHelper_GetAllocStats_Hip(SUNMemoryHelper helper, - SUNMemoryType mem_type, - unsigned long* num_allocations, - unsigned long* num_deallocations, - size_t* bytes_allocated, - size_t* bytes_high_watermark); +SUNErrCode SUNMemoryHelper_GetAllocStats_Hip(SUNMemoryHelper helper, + SUNMemoryType mem_type, + unsigned long* num_allocations, + unsigned long* num_deallocations, + size_t* bytes_allocated, + size_t* bytes_high_watermark); #ifdef __cplusplus } diff --git a/include/sunmemory/sunmemory_sycl.h b/include/sunmemory/sunmemory_sycl.h index 70a0352254..12e38b2e4b 100644 --- a/include/sunmemory/sunmemory_sycl.h +++ b/include/sunmemory/sunmemory_sycl.h @@ -32,36 +32,37 @@ SUNMemoryHelper SUNMemoryHelper_Sycl(SUNContext sunctx); /* SUNMemoryHelper functions */ SUNDIALS_EXPORT -int SUNMemoryHelper_Alloc_Sycl(SUNMemoryHelper helper, SUNMemory* memptr, - size_t mem_size, SUNMemoryType mem_type, - void* queue); +SUNErrCode SUNMemoryHelper_Alloc_Sycl(SUNMemoryHelper helper, SUNMemory* memptr, + size_t mem_size, SUNMemoryType mem_type, + void* queue); SUNDIALS_EXPORT SUNMemoryHelper SUNMemoryHelper_Clone_Sycl(SUNMemoryHelper helper); SUNDIALS_EXPORT -int SUNMemoryHelper_Dealloc_Sycl(SUNMemoryHelper helper, SUNMemory mem, - void* queue); +SUNErrCode SUNMemoryHelper_Dealloc_Sycl(SUNMemoryHelper helper, SUNMemory mem, + void* queue); SUNDIALS_EXPORT -int SUNMemoryHelper_Copy_Sycl(SUNMemoryHelper helper, SUNMemory dst, - SUNMemory src, size_t memory_size, void* queue); +SUNErrCode SUNMemoryHelper_Copy_Sycl(SUNMemoryHelper helper, SUNMemory dst, + SUNMemory src, size_t memory_size, + void* queue); SUNDIALS_EXPORT -int SUNMemoryHelper_CopyAsync_Sycl(SUNMemoryHelper helper, SUNMemory dst, - SUNMemory src, size_t memory_size, - void* queue); +SUNErrCode SUNMemoryHelper_CopyAsync_Sycl(SUNMemoryHelper helper, SUNMemory dst, + SUNMemory src, size_t memory_size, + void* queue); SUNDIALS_EXPORT -int SUNMemoryHelper_Destroy_Sycl(SUNMemoryHelper helper); +SUNErrCode SUNMemoryHelper_Destroy_Sycl(SUNMemoryHelper helper); SUNDIALS_EXPORT -int SUNMemoryHelper_GetAllocStats_Sycl(SUNMemoryHelper helper, - SUNMemoryType mem_type, - unsigned long* num_allocations, - unsigned long* num_deallocations, - size_t* bytes_allocated, - size_t* bytes_high_watermark); +SUNErrCode SUNMemoryHelper_GetAllocStats_Sycl(SUNMemoryHelper helper, + SUNMemoryType mem_type, + unsigned long* num_allocations, + unsigned long* num_deallocations, + size_t* bytes_allocated, + size_t* bytes_high_watermark); #ifdef __cplusplus } diff --git a/include/sunmemory/sunmemory_system.h b/include/sunmemory/sunmemory_system.h index b6a4846e72..69b26ff964 100644 --- a/include/sunmemory/sunmemory_system.h +++ b/include/sunmemory/sunmemory_system.h @@ -31,31 +31,32 @@ SUNMemoryHelper SUNMemoryHelper_Sys(SUNContext sunctx); /* SUNMemoryHelper functions */ SUNDIALS_EXPORT -int SUNMemoryHelper_Alloc_Sys(SUNMemoryHelper helper, SUNMemory* memptr, - size_t mem_size, SUNMemoryType mem_type, - void* queue); +SUNErrCode SUNMemoryHelper_Alloc_Sys(SUNMemoryHelper helper, SUNMemory* memptr, + size_t mem_size, SUNMemoryType mem_type, + void* queue); SUNDIALS_EXPORT -int SUNMemoryHelper_Dealloc_Sys(SUNMemoryHelper helper, SUNMemory mem, - void* queue); +SUNErrCode SUNMemoryHelper_Dealloc_Sys(SUNMemoryHelper helper, SUNMemory mem, + void* queue); SUNDIALS_EXPORT -int SUNMemoryHelper_Copy_Sys(SUNMemoryHelper helper, SUNMemory dst, - SUNMemory src, size_t memory_size, void* queue); +SUNErrCode SUNMemoryHelper_Copy_Sys(SUNMemoryHelper helper, SUNMemory dst, + SUNMemory src, size_t memory_size, + void* queue); SUNDIALS_EXPORT -int SUNMemoryHelper_GetAllocStats_Sys(SUNMemoryHelper helper, - SUNMemoryType mem_type, - unsigned long* num_allocations, - unsigned long* num_deallocations, - size_t* bytes_allocated, - size_t* bytes_high_watermark); +SUNErrCode SUNMemoryHelper_GetAllocStats_Sys(SUNMemoryHelper helper, + SUNMemoryType mem_type, + unsigned long* num_allocations, + unsigned long* num_deallocations, + size_t* bytes_allocated, + size_t* bytes_high_watermark); SUNDIALS_EXPORT SUNMemoryHelper SUNMemoryHelper_Clone_Sys(SUNMemoryHelper helper); SUNDIALS_EXPORT -int SUNMemoryHelper_Destroy_Sys(SUNMemoryHelper helper); +SUNErrCode SUNMemoryHelper_Destroy_Sys(SUNMemoryHelper helper); #ifdef __cplusplus } diff --git a/src/arkode/arkode.c b/src/arkode/arkode.c index b3437c4d10..d0219eeaf6 100644 --- a/src/arkode/arkode.c +++ b/src/arkode/arkode.c @@ -1443,7 +1443,7 @@ int arkInit(ARKodeMem ark_mem, sunrealtype t0, N_Vector y0, int init_type) /* Reset error controller object */ retval = SUNAdaptController_Reset(ark_mem->hadapt_mem->hcontroller); - if (retval != SUNADAPTCONTROLLER_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARK_CONTROLLER_ERR, __LINE__, __func__, __FILE__, "Unable to reset error controller object"); @@ -2663,7 +2663,7 @@ int arkCompleteStep(ARKodeMem ark_mem, sunrealtype dsm) /* Notify time step controller object of successful step */ retval = SUNAdaptController_UpdateH(ark_mem->hadapt_mem->hcontroller, ark_mem->h, dsm); - if (retval != SUNADAPTCONTROLLER_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARK_CONTROLLER_ERR, __LINE__, __func__, __FILE__, "Failure updating controller object"); diff --git a/src/arkode/arkode_adapt.c b/src/arkode/arkode_adapt.c index 814c441b18..775621280a 100644 --- a/src/arkode/arkode_adapt.c +++ b/src/arkode/arkode_adapt.c @@ -121,7 +121,7 @@ int arkAdapt(void* arkode_mem, ARKodeHAdaptMem hadapt_mem, N_Vector ycur, } retval = SUNAdaptController_EstimateStep(hadapt_mem->hcontroller, hcur, controller_order, dsm, &h_acc); - if (retval != SUNADAPTCONTROLLER_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARK_CONTROLLER_ERR, __LINE__, __func__, __FILE__, "SUNAdaptController_EstimateStep failure."); diff --git a/src/arkode/arkode_arkstep_io.c b/src/arkode/arkode_arkstep_io.c index b2ef652c80..e3a7de6549 100644 --- a/src/arkode/arkode_arkstep_io.c +++ b/src/arkode/arkode_arkstep_io.c @@ -765,7 +765,7 @@ int ARKStepSetOptimalParams(void* arkode_mem) /* Remove current SUNAdaptController object */ retval = SUNAdaptController_Space(hadapt_mem->hcontroller, &lenrw, &leniw); - if (retval == SUNADAPTCONTROLLER_SUCCESS) + if (retval == SUN_SUCCESS) { ark_mem->liw -= leniw; ark_mem->lrw -= lenrw; @@ -774,7 +774,7 @@ int ARKStepSetOptimalParams(void* arkode_mem) { retval = SUNAdaptController_Destroy(hadapt_mem->hcontroller); ark_mem->hadapt_mem->owncontroller = SUNFALSE; - if (retval != SUNADAPTCONTROLLER_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARK_MEM_FAIL, __LINE__, __func__, __FILE__, "SUNAdaptController_Destroy failure"); @@ -1012,7 +1012,7 @@ int ARKStepSetOptimalParams(void* arkode_mem) hadapt_mem->owncontroller = SUNTRUE; retval = SUNAdaptController_Space(hadapt_mem->hcontroller, &lenrw, &leniw); - if (retval == SUNADAPTCONTROLLER_SUCCESS) + if (retval == SUN_SUCCESS) { ark_mem->liw += leniw; ark_mem->lrw += lenrw; diff --git a/src/arkode/arkode_erkstep_io.c b/src/arkode/arkode_erkstep_io.c index 90c397c562..0e5b0055ec 100644 --- a/src/arkode/arkode_erkstep_io.c +++ b/src/arkode/arkode_erkstep_io.c @@ -428,7 +428,7 @@ int ERKStepSetDefaults(void* arkode_mem) /* Remove current SUNAdaptController object, and replace with "PI" */ retval = SUNAdaptController_Space(ark_mem->hadapt_mem->hcontroller, &lenrw, &leniw); - if (retval == SUNADAPTCONTROLLER_SUCCESS) + if (retval == SUN_SUCCESS) { ark_mem->liw -= leniw; ark_mem->lrw -= lenrw; @@ -437,7 +437,7 @@ int ERKStepSetDefaults(void* arkode_mem) { retval = SUNAdaptController_Destroy(ark_mem->hadapt_mem->hcontroller); ark_mem->hadapt_mem->owncontroller = SUNFALSE; - if (retval != SUNADAPTCONTROLLER_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARK_MEM_FAIL, __LINE__, __func__, __FILE__, "SUNAdaptController_Destroy failure"); @@ -455,7 +455,7 @@ int ERKStepSetDefaults(void* arkode_mem) ark_mem->hadapt_mem->owncontroller = SUNTRUE; retval = SUNAdaptController_Space(ark_mem->hadapt_mem->hcontroller, &lenrw, &leniw); - if (retval == SUNADAPTCONTROLLER_SUCCESS) + if (retval == SUN_SUCCESS) { ark_mem->liw += leniw; ark_mem->lrw += lenrw; diff --git a/src/arkode/arkode_io.c b/src/arkode/arkode_io.c index f035f85a65..9e645ccac7 100644 --- a/src/arkode/arkode_io.c +++ b/src/arkode/arkode_io.c @@ -276,7 +276,7 @@ int arkSetAdaptController(void* arkode_mem, SUNAdaptController C) (delete if owned, and then nullify pointer) */ retval = SUNAdaptController_Space(ark_mem->hadapt_mem->hcontroller, &lenrw, &leniw); - if (retval == SUNADAPTCONTROLLER_SUCCESS) + if (retval == SUN_SUCCESS) { ark_mem->liw -= leniw; ark_mem->lrw -= lenrw; @@ -285,7 +285,7 @@ int arkSetAdaptController(void* arkode_mem, SUNAdaptController C) { retval = SUNAdaptController_Destroy(ark_mem->hadapt_mem->hcontroller); ark_mem->hadapt_mem->owncontroller = SUNFALSE; - if (retval != SUNADAPTCONTROLLER_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARK_MEM_FAIL, __LINE__, __func__, __FILE__, "SUNAdaptController_Destroy failure"); @@ -310,7 +310,7 @@ int arkSetAdaptController(void* arkode_mem, SUNAdaptController C) /* Attach new SUNAdaptController object */ retval = SUNAdaptController_Space(C, &lenrw, &leniw); - if (retval == SUNADAPTCONTROLLER_SUCCESS) + if (retval == SUN_SUCCESS) { ark_mem->liw += leniw; ark_mem->lrw += lenrw; @@ -392,7 +392,7 @@ int arkSetInitStep(void* arkode_mem, sunrealtype hin) /* Reset error controller (e.g., error and step size history) */ retval = SUNAdaptController_Reset(ark_mem->hadapt_mem->hcontroller); - if (retval != SUNADAPTCONTROLLER_SUCCESS) { return (ARK_CONTROLLER_ERR); } + if (retval != SUN_SUCCESS) { return (ARK_CONTROLLER_ERR); } return (ARK_SUCCESS); } @@ -857,7 +857,7 @@ int arkSetAdaptivityMethod(void* arkode_mem, int imethod, int idefault, int pq, (delete if owned, and then nullify pointer) */ retval = SUNAdaptController_Space(ark_mem->hadapt_mem->hcontroller, &lenrw, &leniw); - if (retval == SUNADAPTCONTROLLER_SUCCESS) + if (retval == SUN_SUCCESS) { ark_mem->liw -= leniw; ark_mem->lrw -= lenrw; @@ -866,7 +866,7 @@ int arkSetAdaptivityMethod(void* arkode_mem, int imethod, int idefault, int pq, { retval = SUNAdaptController_Destroy(ark_mem->hadapt_mem->hcontroller); ark_mem->hadapt_mem->owncontroller = SUNFALSE; - if (retval != SUNADAPTCONTROLLER_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARK_MEM_FAIL, __LINE__, __func__, __FILE__, "SUNAdaptController_Destroy failure"); @@ -901,7 +901,7 @@ int arkSetAdaptivityMethod(void* arkode_mem, int imethod, int idefault, int pq, if (idefault != 1) { retval = SUNAdaptController_SetParams_PID(C, k1, -k2, k3); - if (retval != SUNADAPTCONTROLLER_SUCCESS) + if (retval != SUN_SUCCESS) { (void)SUNAdaptController_Destroy(C); arkProcessError(ark_mem, ARK_CONTROLLER_ERR, __LINE__, __func__, @@ -921,7 +921,7 @@ int arkSetAdaptivityMethod(void* arkode_mem, int imethod, int idefault, int pq, if (idefault != 1) { retval = SUNAdaptController_SetParams_PI(C, k1, -k2); - if (retval != SUNADAPTCONTROLLER_SUCCESS) + if (retval != SUN_SUCCESS) { (void)SUNAdaptController_Destroy(C); arkProcessError(ark_mem, ARK_CONTROLLER_ERR, __LINE__, __func__, @@ -941,7 +941,7 @@ int arkSetAdaptivityMethod(void* arkode_mem, int imethod, int idefault, int pq, if (idefault != 1) { retval = SUNAdaptController_SetParams_I(C, k1); - if (retval != SUNADAPTCONTROLLER_SUCCESS) + if (retval != SUN_SUCCESS) { (void)SUNAdaptController_Destroy(C); arkProcessError(ark_mem, ARK_CONTROLLER_ERR, __LINE__, __func__, @@ -961,7 +961,7 @@ int arkSetAdaptivityMethod(void* arkode_mem, int imethod, int idefault, int pq, if (idefault != 1) { retval = SUNAdaptController_SetParams_ExpGus(C, k1, k2); - if (retval != SUNADAPTCONTROLLER_SUCCESS) + if (retval != SUN_SUCCESS) { (void)SUNAdaptController_Destroy(C); arkProcessError(ark_mem, ARK_CONTROLLER_ERR, __LINE__, __func__, @@ -981,7 +981,7 @@ int arkSetAdaptivityMethod(void* arkode_mem, int imethod, int idefault, int pq, if (idefault != 1) { retval = SUNAdaptController_SetParams_ImpGus(C, k1, k2); - if (retval != SUNADAPTCONTROLLER_SUCCESS) + if (retval != SUN_SUCCESS) { (void)SUNAdaptController_Destroy(C); arkProcessError(ark_mem, ARK_CONTROLLER_ERR, __LINE__, __func__, @@ -1001,7 +1001,7 @@ int arkSetAdaptivityMethod(void* arkode_mem, int imethod, int idefault, int pq, if (idefault != 1) { retval = SUNAdaptController_SetParams_ImExGus(C, k1, k2, k3, k3); - if (retval != SUNADAPTCONTROLLER_SUCCESS) + if (retval != SUN_SUCCESS) { (void)SUNAdaptController_Destroy(C); arkProcessError(ark_mem, ARK_CONTROLLER_ERR, __LINE__, __func__, @@ -1018,7 +1018,7 @@ int arkSetAdaptivityMethod(void* arkode_mem, int imethod, int idefault, int pq, /* Attach new SUNAdaptController object */ retval = SUNAdaptController_Space(C, &lenrw, &leniw); - if (retval == SUNADAPTCONTROLLER_SUCCESS) + if (retval == SUN_SUCCESS) { ark_mem->liw += leniw; ark_mem->lrw += lenrw; @@ -1058,7 +1058,7 @@ int arkSetAdaptivityFn(void* arkode_mem, ARKAdaptFn hfun, void* h_data) (delete if owned, and then nullify pointer) */ retval = SUNAdaptController_Space(ark_mem->hadapt_mem->hcontroller, &lenrw, &leniw); - if (retval == SUNADAPTCONTROLLER_SUCCESS) + if (retval == SUN_SUCCESS) { ark_mem->liw -= leniw; ark_mem->lrw -= lenrw; @@ -1067,7 +1067,7 @@ int arkSetAdaptivityFn(void* arkode_mem, ARKAdaptFn hfun, void* h_data) { retval = SUNAdaptController_Destroy(ark_mem->hadapt_mem->hcontroller); ark_mem->hadapt_mem->owncontroller = SUNFALSE; - if (retval != SUNADAPTCONTROLLER_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARK_MEM_FAIL, __LINE__, __func__, __FILE__, "SUNAdaptController_Destroy failure"); @@ -1101,7 +1101,7 @@ int arkSetAdaptivityFn(void* arkode_mem, ARKAdaptFn hfun, void* h_data) /* Attach new SUNAdaptController object */ retval = SUNAdaptController_Space(C, &lenrw, &leniw); - if (retval == SUNADAPTCONTROLLER_SUCCESS) + if (retval == SUN_SUCCESS) { ark_mem->liw += leniw; ark_mem->lrw += lenrw; @@ -1220,7 +1220,7 @@ int arkSetErrorBias(void* arkode_mem, sunrealtype bias) { retval = SUNAdaptController_SetErrorBias(hadapt_mem->hcontroller, bias); } - if (retval != SUNADAPTCONTROLLER_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARK_CONTROLLER_ERR, __LINE__, __func__, __FILE__, "SUNAdaptController_SetErrorBias failure"); diff --git a/src/arkode/arkode_user_controller.c b/src/arkode/arkode_user_controller.c index e9790c06a5..8001439946 100644 --- a/src/arkode/arkode_user_controller.c +++ b/src/arkode/arkode_user_controller.c @@ -112,11 +112,8 @@ int SUNAdaptController_EstimateStep_ARKUserControl(SUNAdaptController C, int retval = SC_HADAPT(C)(SC_ARKMEM(C)->ycur, ttmp, h, SC_HP(C), SC_HPP(C), dsm, SC_EP(C), SC_EPP(C), SC_ARKMEM(C)->hadapt_mem->q, SC_ARKMEM(C)->hadapt_mem->p, hnew, SC_DATA(C)); - if (retval != SUNADAPTCONTROLLER_SUCCESS) - { - return (SUNADAPTCONTROLLER_USER_FCN_FAIL); - } - return SUNADAPTCONTROLLER_SUCCESS; + if (retval != SUN_SUCCESS) { return (SUN_ERR_USER_FCN_FAIL); } + return SUN_SUCCESS; } int SUNAdaptController_Reset_ARKUserControl(SUNAdaptController C) @@ -125,7 +122,7 @@ int SUNAdaptController_Reset_ARKUserControl(SUNAdaptController C) SC_EPP(C) = SUN_RCONST(1.0); SC_HP(C) = SUN_RCONST(0.0); SC_HPP(C) = SUN_RCONST(0.0); - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } int SUNAdaptController_Write_ARKUserControl(SUNAdaptController C, FILE* fptr) @@ -143,7 +140,7 @@ int SUNAdaptController_Write_ARKUserControl(SUNAdaptController C, FILE* fptr) fprintf(fptr, " epp = %12g\n", SC_EPP(C)); #endif fprintf(fptr, " hadapt_data = %p\n", SC_DATA(C)); - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } int SUNAdaptController_UpdateH_ARKUserControl(SUNAdaptController C, @@ -153,7 +150,7 @@ int SUNAdaptController_UpdateH_ARKUserControl(SUNAdaptController C, SC_HP(C) = h; SC_EPP(C) = SC_EP(C); SC_EP(C) = dsm; - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } int SUNAdaptController_Space_ARKUserControl(SUNAdaptController C, @@ -161,5 +158,5 @@ int SUNAdaptController_Space_ARKUserControl(SUNAdaptController C, { *lenrw = 4; *leniw = 2; - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } diff --git a/src/sunadaptcontroller/imexgus/fmod/fsunadaptcontroller_imexgus_mod.c b/src/sunadaptcontroller/imexgus/fmod/fsunadaptcontroller_imexgus_mod.c index 18ab594868..1800859fc5 100644 --- a/src/sunadaptcontroller/imexgus/fmod/fsunadaptcontroller_imexgus_mod.c +++ b/src/sunadaptcontroller/imexgus/fmod/fsunadaptcontroller_imexgus_mod.c @@ -227,15 +227,15 @@ SWIGEXPORT int _wrap_FSUNAdaptController_SetParams_ImExGus(SUNAdaptController fa sunrealtype arg3 ; sunrealtype arg4 ; sunrealtype arg5 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (sunrealtype)(*farg2); arg3 = (sunrealtype)(*farg3); arg4 = (sunrealtype)(*farg4); arg5 = (sunrealtype)(*farg5); - result = (int)SUNAdaptController_SetParams_ImExGus(arg1,arg2,arg3,arg4,arg5); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_SetParams_ImExGus(arg1,arg2,arg3,arg4,arg5); + fresult = (SUNErrCode)(result); return fresult; } @@ -259,15 +259,15 @@ SWIGEXPORT int _wrap_FSUNAdaptController_EstimateStep_ImExGus(SUNAdaptController int arg3 ; sunrealtype arg4 ; sunrealtype *arg5 = (sunrealtype *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (sunrealtype)(*farg2); arg3 = (int)(*farg3); arg4 = (sunrealtype)(*farg4); arg5 = (sunrealtype *)(farg5); - result = (int)SUNAdaptController_EstimateStep_ImExGus(arg1,arg2,arg3,arg4,arg5); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_EstimateStep_ImExGus(arg1,arg2,arg3,arg4,arg5); + fresult = (SUNErrCode)(result); return fresult; } @@ -275,11 +275,11 @@ SWIGEXPORT int _wrap_FSUNAdaptController_EstimateStep_ImExGus(SUNAdaptController SWIGEXPORT int _wrap_FSUNAdaptController_Reset_ImExGus(SUNAdaptController farg1) { int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); - result = (int)SUNAdaptController_Reset_ImExGus(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_Reset_ImExGus(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -287,11 +287,11 @@ SWIGEXPORT int _wrap_FSUNAdaptController_Reset_ImExGus(SUNAdaptController farg1) SWIGEXPORT int _wrap_FSUNAdaptController_SetDefaults_ImExGus(SUNAdaptController farg1) { int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); - result = (int)SUNAdaptController_SetDefaults_ImExGus(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_SetDefaults_ImExGus(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -300,12 +300,12 @@ SWIGEXPORT int _wrap_FSUNAdaptController_Write_ImExGus(SUNAdaptController farg1, int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; FILE *arg2 = (FILE *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (FILE *)(farg2); - result = (int)SUNAdaptController_Write_ImExGus(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_Write_ImExGus(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -314,12 +314,12 @@ SWIGEXPORT int _wrap_FSUNAdaptController_SetErrorBias_ImExGus(SUNAdaptController int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; sunrealtype arg2 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (sunrealtype)(*farg2); - result = (int)SUNAdaptController_SetErrorBias_ImExGus(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_SetErrorBias_ImExGus(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -329,13 +329,13 @@ SWIGEXPORT int _wrap_FSUNAdaptController_UpdateH_ImExGus(SUNAdaptController farg SUNAdaptController arg1 = (SUNAdaptController) 0 ; sunrealtype arg2 ; sunrealtype arg3 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (sunrealtype)(*farg2); arg3 = (sunrealtype)(*farg3); - result = (int)SUNAdaptController_UpdateH_ImExGus(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_UpdateH_ImExGus(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -345,13 +345,13 @@ SWIGEXPORT int _wrap_FSUNAdaptController_Space_ImExGus(SUNAdaptController farg1, SUNAdaptController arg1 = (SUNAdaptController) 0 ; long *arg2 = (long *) 0 ; long *arg3 = (long *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (long *)(farg2); arg3 = (long *)(farg3); - result = (int)SUNAdaptController_Space_ImExGus(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_Space_ImExGus(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } diff --git a/src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c b/src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c index f20c7e9799..3516ecd6fd 100644 --- a/src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c +++ b/src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c @@ -18,7 +18,10 @@ #include #include #include -#include +#include + +#include "sundials/priv/sundials_errors_impl.h" +#include "sundials/sundials_errors.h" /* --------------- * Macro accessors @@ -55,15 +58,15 @@ SUNAdaptController SUNAdaptController_ImExGus(SUNContext sunctx) { + SUNFunctionBegin(sunctx); + SUNAdaptController C; SUNAdaptControllerContent_ImExGus content; - if (sunctx == NULL) { return NULL; } - /* Create an empty controller object */ C = NULL; C = SUNAdaptController_NewEmpty(sunctx); - if (C == NULL) { return (NULL); } + SUNCheckLastErrNull(); /* Attach operations */ C->ops->gettype = SUNAdaptController_GetType_ImExGus; @@ -78,18 +81,14 @@ SUNAdaptController SUNAdaptController_ImExGus(SUNContext sunctx) /* Create content */ content = NULL; content = (SUNAdaptControllerContent_ImExGus)malloc(sizeof *content); - if (content == NULL) - { - (void)SUNAdaptController_Destroy(C); - return (NULL); - } + SUNAssertNull(content, SUN_ERR_MALLOC_FAIL); /* Attach content */ C->content = content; /* Fill content with default/reset values */ - SUNAdaptController_SetDefaults_ImExGus(C); - SUNAdaptController_Reset_ImExGus(C); + SUNCheckCallNull(SUNAdaptController_SetDefaults_ImExGus(C)); + SUNCheckCallNull(SUNAdaptController_Reset_ImExGus(C)); return (C); } @@ -98,16 +97,16 @@ SUNAdaptController SUNAdaptController_ImExGus(SUNContext sunctx) * Function to set ImExGus parameters */ -int SUNAdaptController_SetParams_ImExGus(SUNAdaptController C, sunrealtype k1e, - sunrealtype k2e, sunrealtype k1i, - sunrealtype k2i) +SUNErrCode SUNAdaptController_SetParams_ImExGus(SUNAdaptController C, + sunrealtype k1e, sunrealtype k2e, + sunrealtype k1i, sunrealtype k2i) { - if (C == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } + SUNFunctionBegin(C->sunctx); SACIMEXGUS_K1E(C) = k1e; SACIMEXGUS_K2E(C) = k2e; SACIMEXGUS_K1I(C) = k1i; SACIMEXGUS_K2I(C) = k2i; - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } /* ----------------------------------------------------------------- @@ -119,10 +118,15 @@ SUNAdaptController_Type SUNAdaptController_GetType_ImExGus(SUNAdaptController C) return SUN_ADAPTCONTROLLER_H; } -int SUNAdaptController_EstimateStep_ImExGus(SUNAdaptController C, sunrealtype h, - int p, sunrealtype dsm, - sunrealtype* hnew) +SUNErrCode SUNAdaptController_EstimateStep_ImExGus(SUNAdaptController C, + sunrealtype h, int p, + sunrealtype dsm, + sunrealtype* hnew) { + SUNFunctionBegin(C->sunctx); + + SUNAssert(hnew, SUN_ERR_ARG_CORRUPT); + /* order parameter to use */ const int ord = p + 1; @@ -139,8 +143,6 @@ int SUNAdaptController_EstimateStep_ImExGus(SUNAdaptController C, sunrealtype h, const sunrealtype e2 = e1 / SUNMAX(SACIMEXGUS_EP(C), TINY); const sunrealtype hrat = h / SACIMEXGUS_HP(C); - if (C == NULL || hnew == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } - /* compute estimated time step size, modifying the first step formula */ if (SACIMEXGUS_FIRSTSTEP(C)) { *hnew = h * SUNRpowerR(e, k); } else @@ -150,30 +152,31 @@ int SUNAdaptController_EstimateStep_ImExGus(SUNAdaptController C, sunrealtype h, } /* return with success */ - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } -int SUNAdaptController_Reset_ImExGus(SUNAdaptController C) +SUNErrCode SUNAdaptController_Reset_ImExGus(SUNAdaptController C) { SACIMEXGUS_EP(C) = SUN_RCONST(1.0); SACIMEXGUS_FIRSTSTEP(C) = SUNTRUE; - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } -int SUNAdaptController_SetDefaults_ImExGus(SUNAdaptController C) +SUNErrCode SUNAdaptController_SetDefaults_ImExGus(SUNAdaptController C) { - if (C == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } + SUNFunctionBegin(C->sunctx); SACIMEXGUS_K1E(C) = DEFAULT_K1E; SACIMEXGUS_K2E(C) = DEFAULT_K2E; SACIMEXGUS_K1I(C) = DEFAULT_K1I; SACIMEXGUS_K2I(C) = DEFAULT_K2I; SACIMEXGUS_BIAS(C) = DEFAULT_BIAS; - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } -int SUNAdaptController_Write_ImExGus(SUNAdaptController C, FILE* fptr) +SUNErrCode SUNAdaptController_Write_ImExGus(SUNAdaptController C, FILE* fptr) { - if (C == NULL || fptr == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } + SUNFunctionBegin(C->sunctx); + SUNAssert(fptr, SUN_ERR_ARG_CORRUPT); fprintf(fptr, "ImEx Gustafsson SUNAdaptController module:\n"); #if defined(SUNDIALS_EXTENDED_PRECISION) fprintf(fptr, " k1e = %32Lg\n", SACIMEXGUS_K1E(C)); @@ -192,37 +195,37 @@ int SUNAdaptController_Write_ImExGus(SUNAdaptController C, FILE* fptr) fprintf(fptr, " previous error = %16g\n", SACIMEXGUS_EP(C)); fprintf(fptr, " previous step = %16g\n", SACIMEXGUS_HP(C)); #endif - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } -int SUNAdaptController_SetErrorBias_ImExGus(SUNAdaptController C, sunrealtype bias) +SUNErrCode SUNAdaptController_SetErrorBias_ImExGus(SUNAdaptController C, + sunrealtype bias) { - if (C == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } + SUNFunctionBegin(C->sunctx); /* set allowed value, otherwise set default */ if (bias <= SUN_RCONST(0.0)) { SACIMEXGUS_BIAS(C) = DEFAULT_BIAS; } else { SACIMEXGUS_BIAS(C) = bias; } - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } -int SUNAdaptController_UpdateH_ImExGus(SUNAdaptController C, sunrealtype h, - sunrealtype dsm) +SUNErrCode SUNAdaptController_UpdateH_ImExGus(SUNAdaptController C, + sunrealtype h, sunrealtype dsm) { - if (C == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } + SUNFunctionBegin(C->sunctx); SACIMEXGUS_EP(C) = SACIMEXGUS_BIAS(C) * dsm; SACIMEXGUS_HP(C) = h; SACIMEXGUS_FIRSTSTEP(C) = SUNFALSE; - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } -int SUNAdaptController_Space_ImExGus(SUNAdaptController C, long int* lenrw, - long int* leniw) +SUNErrCode SUNAdaptController_Space_ImExGus(SUNAdaptController C, + long int* lenrw, long int* leniw) { - if (C == NULL || lenrw == NULL || leniw == NULL) - { - return SUNADAPTCONTROLLER_ILL_INPUT; - } + SUNFunctionBegin(C->sunctx); + SUNAssert(lenrw, SUN_ERR_ARG_CORRUPT); + SUNAssert(leniw, SUN_ERR_ARG_CORRUPT); *lenrw = 7; *leniw = 1; - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } diff --git a/src/sunadaptcontroller/soderlind/fmod/fsunadaptcontroller_soderlind_mod.c b/src/sunadaptcontroller/soderlind/fmod/fsunadaptcontroller_soderlind_mod.c index 394e83cd3e..e62db42c44 100644 --- a/src/sunadaptcontroller/soderlind/fmod/fsunadaptcontroller_soderlind_mod.c +++ b/src/sunadaptcontroller/soderlind/fmod/fsunadaptcontroller_soderlind_mod.c @@ -228,7 +228,7 @@ SWIGEXPORT int _wrap_FSUNAdaptController_SetParams_Soderlind(SUNAdaptController sunrealtype arg4 ; sunrealtype arg5 ; sunrealtype arg6 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (sunrealtype)(*farg2); @@ -236,8 +236,8 @@ SWIGEXPORT int _wrap_FSUNAdaptController_SetParams_Soderlind(SUNAdaptController arg4 = (sunrealtype)(*farg4); arg5 = (sunrealtype)(*farg5); arg6 = (sunrealtype)(*farg6); - result = (int)SUNAdaptController_SetParams_Soderlind(arg1,arg2,arg3,arg4,arg5,arg6); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_SetParams_Soderlind(arg1,arg2,arg3,arg4,arg5,arg6); + fresult = (SUNErrCode)(result); return fresult; } @@ -261,15 +261,15 @@ SWIGEXPORT int _wrap_FSUNAdaptController_EstimateStep_Soderlind(SUNAdaptControll int arg3 ; sunrealtype arg4 ; sunrealtype *arg5 = (sunrealtype *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (sunrealtype)(*farg2); arg3 = (int)(*farg3); arg4 = (sunrealtype)(*farg4); arg5 = (sunrealtype *)(farg5); - result = (int)SUNAdaptController_EstimateStep_Soderlind(arg1,arg2,arg3,arg4,arg5); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_EstimateStep_Soderlind(arg1,arg2,arg3,arg4,arg5); + fresult = (SUNErrCode)(result); return fresult; } @@ -277,11 +277,11 @@ SWIGEXPORT int _wrap_FSUNAdaptController_EstimateStep_Soderlind(SUNAdaptControll SWIGEXPORT int _wrap_FSUNAdaptController_Reset_Soderlind(SUNAdaptController farg1) { int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); - result = (int)SUNAdaptController_Reset_Soderlind(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_Reset_Soderlind(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -289,11 +289,11 @@ SWIGEXPORT int _wrap_FSUNAdaptController_Reset_Soderlind(SUNAdaptController farg SWIGEXPORT int _wrap_FSUNAdaptController_SetDefaults_Soderlind(SUNAdaptController farg1) { int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); - result = (int)SUNAdaptController_SetDefaults_Soderlind(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_SetDefaults_Soderlind(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -302,12 +302,12 @@ SWIGEXPORT int _wrap_FSUNAdaptController_Write_Soderlind(SUNAdaptController farg int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; FILE *arg2 = (FILE *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (FILE *)(farg2); - result = (int)SUNAdaptController_Write_Soderlind(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_Write_Soderlind(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -316,12 +316,12 @@ SWIGEXPORT int _wrap_FSUNAdaptController_SetErrorBias_Soderlind(SUNAdaptControll int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; sunrealtype arg2 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (sunrealtype)(*farg2); - result = (int)SUNAdaptController_SetErrorBias_Soderlind(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_SetErrorBias_Soderlind(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -331,13 +331,13 @@ SWIGEXPORT int _wrap_FSUNAdaptController_UpdateH_Soderlind(SUNAdaptController fa SUNAdaptController arg1 = (SUNAdaptController) 0 ; sunrealtype arg2 ; sunrealtype arg3 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (sunrealtype)(*farg2); arg3 = (sunrealtype)(*farg3); - result = (int)SUNAdaptController_UpdateH_Soderlind(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_UpdateH_Soderlind(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -347,13 +347,13 @@ SWIGEXPORT int _wrap_FSUNAdaptController_Space_Soderlind(SUNAdaptController farg SUNAdaptController arg1 = (SUNAdaptController) 0 ; long *arg2 = (long *) 0 ; long *arg3 = (long *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (long *)(farg2); arg3 = (long *)(farg3); - result = (int)SUNAdaptController_Space_Soderlind(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_Space_Soderlind(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -376,14 +376,14 @@ SWIGEXPORT int _wrap_FSUNAdaptController_SetParams_PID(SUNAdaptController farg1, sunrealtype arg2 ; sunrealtype arg3 ; sunrealtype arg4 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (sunrealtype)(*farg2); arg3 = (sunrealtype)(*farg3); arg4 = (sunrealtype)(*farg4); - result = (int)SUNAdaptController_SetParams_PID(arg1,arg2,arg3,arg4); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_SetParams_PID(arg1,arg2,arg3,arg4); + fresult = (SUNErrCode)(result); return fresult; } @@ -405,13 +405,13 @@ SWIGEXPORT int _wrap_FSUNAdaptController_SetParams_PI(SUNAdaptController farg1, SUNAdaptController arg1 = (SUNAdaptController) 0 ; sunrealtype arg2 ; sunrealtype arg3 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (sunrealtype)(*farg2); arg3 = (sunrealtype)(*farg3); - result = (int)SUNAdaptController_SetParams_PI(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_SetParams_PI(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -432,12 +432,12 @@ SWIGEXPORT int _wrap_FSUNAdaptController_SetParams_I(SUNAdaptController farg1, d int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; sunrealtype arg2 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (sunrealtype)(*farg2); - result = (int)SUNAdaptController_SetParams_I(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_SetParams_I(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -459,13 +459,13 @@ SWIGEXPORT int _wrap_FSUNAdaptController_SetParams_ExpGus(SUNAdaptController far SUNAdaptController arg1 = (SUNAdaptController) 0 ; sunrealtype arg2 ; sunrealtype arg3 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (sunrealtype)(*farg2); arg3 = (sunrealtype)(*farg3); - result = (int)SUNAdaptController_SetParams_ExpGus(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_SetParams_ExpGus(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -487,13 +487,13 @@ SWIGEXPORT int _wrap_FSUNAdaptController_SetParams_ImpGus(SUNAdaptController far SUNAdaptController arg1 = (SUNAdaptController) 0 ; sunrealtype arg2 ; sunrealtype arg3 ; - int result; + SUNErrCode result; arg1 = (SUNAdaptController)(farg1); arg2 = (sunrealtype)(*farg2); arg3 = (sunrealtype)(*farg3); - result = (int)SUNAdaptController_SetParams_ImpGus(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNAdaptController_SetParams_ImpGus(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } diff --git a/src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c b/src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c index e1dc08f3d4..a67ec85a1f 100644 --- a/src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c +++ b/src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c @@ -18,7 +18,10 @@ #include #include #include -#include +#include + +#include "sundials/priv/sundials_errors_impl.h" +#include "sundials/sundials_errors.h" /* --------------- * Macro accessors @@ -69,15 +72,15 @@ SUNAdaptController SUNAdaptController_Soderlind(SUNContext sunctx) { + SUNFunctionBegin(sunctx); + SUNAdaptController C; SUNAdaptControllerContent_Soderlind content; - if (sunctx == NULL) { return NULL; } - /* Create an empty controller object */ C = NULL; C = SUNAdaptController_NewEmpty(sunctx); - if (C == NULL) { return (NULL); } + SUNCheckLastErrNull(); /* Attach operations */ C->ops->gettype = SUNAdaptController_GetType_Soderlind; @@ -92,18 +95,14 @@ SUNAdaptController SUNAdaptController_Soderlind(SUNContext sunctx) /* Create content */ content = NULL; content = (SUNAdaptControllerContent_Soderlind)malloc(sizeof *content); - if (content == NULL) - { - (void)SUNAdaptController_Destroy(C); - return (NULL); - } + SUNAssertNull(content, SUN_ERR_MALLOC_FAIL); /* Attach content */ C->content = content; /* Fill content with default/reset values */ - SUNAdaptController_SetDefaults_Soderlind(C); - SUNAdaptController_Reset_Soderlind(C); + SUNCheckCallNull(SUNAdaptController_SetDefaults_Soderlind(C)); + SUNCheckCallNull(SUNAdaptController_Reset_Soderlind(C)); return (C); } @@ -112,17 +111,18 @@ SUNAdaptController SUNAdaptController_Soderlind(SUNContext sunctx) * Function to set Soderlind parameters */ -int SUNAdaptController_SetParams_Soderlind(SUNAdaptController C, sunrealtype k1, - sunrealtype k2, sunrealtype k3, - sunrealtype k4, sunrealtype k5) +SUNErrCode SUNAdaptController_SetParams_Soderlind(SUNAdaptController C, + sunrealtype k1, + sunrealtype k2, sunrealtype k3, + sunrealtype k4, sunrealtype k5) { - if (C == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } + SUNFunctionBegin(C->sunctx); SODERLIND_K1(C) = k1; SODERLIND_K2(C) = k2; SODERLIND_K3(C) = k3; SODERLIND_K4(C) = k4; SODERLIND_K5(C) = k5; - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } /* ----------------------------------------------------------------- @@ -131,18 +131,15 @@ int SUNAdaptController_SetParams_Soderlind(SUNAdaptController C, sunrealtype k1, SUNAdaptController SUNAdaptController_PID(SUNContext sunctx) { - SUNAdaptController C; - int retval; - if (sunctx == NULL) { return NULL; } - C = SUNAdaptController_Soderlind(sunctx); - if (C == NULL) { return NULL; } - retval = SUNAdaptController_SetParams_PID(C, DEFAULT_PID_K1, DEFAULT_PID_K2, - DEFAULT_PID_K3); - if (retval != SUNADAPTCONTROLLER_SUCCESS) - { - (void)SUNAdaptController_Destroy(C); - C = NULL; - } + SUNFunctionBegin(sunctx); + + SUNAdaptController C = SUNAdaptController_Soderlind(sunctx); + SUNCheckLastErrNull(); + + SUNCheckCallNull(SUNAdaptController_SetParams_PID(C, DEFAULT_PID_K1, + DEFAULT_PID_K2, + DEFAULT_PID_K3)); + return (C); } @@ -150,16 +147,16 @@ SUNAdaptController SUNAdaptController_PID(SUNContext sunctx) * Function to set PID parameters */ -int SUNAdaptController_SetParams_PID(SUNAdaptController C, sunrealtype k1, - sunrealtype k2, sunrealtype k3) +SUNErrCode SUNAdaptController_SetParams_PID(SUNAdaptController C, sunrealtype k1, + sunrealtype k2, sunrealtype k3) { - if (C == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } + SUNFunctionBegin(C->sunctx); SODERLIND_K1(C) = k1; SODERLIND_K2(C) = k2; SODERLIND_K3(C) = k3; SODERLIND_K4(C) = SUN_RCONST(0.0); SODERLIND_K5(C) = SUN_RCONST(0.0); - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } /* ----------------------------------------------------------------- @@ -168,17 +165,15 @@ int SUNAdaptController_SetParams_PID(SUNAdaptController C, sunrealtype k1, SUNAdaptController SUNAdaptController_PI(SUNContext sunctx) { + SUNFunctionBegin(sunctx); + SUNAdaptController C; - int retval; - if (sunctx == NULL) { return NULL; } C = SUNAdaptController_Soderlind(sunctx); - if (C == NULL) { return NULL; } - retval = SUNAdaptController_SetParams_PI(C, DEFAULT_PI_K1, DEFAULT_PI_K2); - if (retval != SUNADAPTCONTROLLER_SUCCESS) - { - (void)SUNAdaptController_Destroy(C); - C = NULL; - } + SUNCheckLastErrNull(); + + SUNCheckCallNull( + SUNAdaptController_SetParams_PI(C, DEFAULT_PI_K1, DEFAULT_PI_K2)); + return (C); } @@ -186,16 +181,16 @@ SUNAdaptController SUNAdaptController_PI(SUNContext sunctx) * Function to set PI parameters */ -int SUNAdaptController_SetParams_PI(SUNAdaptController C, sunrealtype k1, - sunrealtype k2) +SUNErrCode SUNAdaptController_SetParams_PI(SUNAdaptController C, sunrealtype k1, + sunrealtype k2) { - if (C == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } + SUNFunctionBegin(C->sunctx); SODERLIND_K1(C) = k1; SODERLIND_K2(C) = k2; SODERLIND_K3(C) = SUN_RCONST(0.0); SODERLIND_K4(C) = SUN_RCONST(0.0); SODERLIND_K5(C) = SUN_RCONST(0.0); - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } /* ----------------------------------------------------------------- @@ -204,17 +199,14 @@ int SUNAdaptController_SetParams_PI(SUNAdaptController C, sunrealtype k1, SUNAdaptController SUNAdaptController_I(SUNContext sunctx) { + SUNFunctionBegin(sunctx); + SUNAdaptController C; - int retval; - if (sunctx == NULL) { return NULL; } C = SUNAdaptController_Soderlind(sunctx); - if (C == NULL) { return NULL; } - retval = SUNAdaptController_SetParams_I(C, DEFAULT_I_K1); - if (retval != SUNADAPTCONTROLLER_SUCCESS) - { - (void)SUNAdaptController_Destroy(C); - C = NULL; - } + SUNCheckLastErrNull(); + + SUNCheckCallNull(SUNAdaptController_SetParams_I(C, DEFAULT_I_K1)); + return (C); } @@ -222,15 +214,15 @@ SUNAdaptController SUNAdaptController_I(SUNContext sunctx) * Function to set PI parameters */ -int SUNAdaptController_SetParams_I(SUNAdaptController C, sunrealtype k1) +SUNErrCode SUNAdaptController_SetParams_I(SUNAdaptController C, sunrealtype k1) { - if (C == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } + SUNFunctionBegin(C->sunctx); SODERLIND_K1(C) = k1; SODERLIND_K2(C) = SUN_RCONST(0.0); SODERLIND_K3(C) = SUN_RCONST(0.0); SODERLIND_K4(C) = SUN_RCONST(0.0); SODERLIND_K5(C) = SUN_RCONST(0.0); - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } /* ----------------------------------------------------------------- @@ -239,18 +231,15 @@ int SUNAdaptController_SetParams_I(SUNAdaptController C, sunrealtype k1) SUNAdaptController SUNAdaptController_ExpGus(SUNContext sunctx) { + SUNFunctionBegin(sunctx); + SUNAdaptController C; - int retval; - if (sunctx == NULL) { return NULL; } C = SUNAdaptController_Soderlind(sunctx); - if (C == NULL) { return NULL; } - retval = SUNAdaptController_SetParams_ExpGus(C, DEFAULT_EXPGUS_K1, - DEFAULT_EXPGUS_K2); - if (retval != SUNADAPTCONTROLLER_SUCCESS) - { - (void)SUNAdaptController_Destroy(C); - C = NULL; - } + SUNCheckLastErrNull(); + + SUNCheckCallNull(SUNAdaptController_SetParams_ExpGus(C, DEFAULT_EXPGUS_K1, + DEFAULT_EXPGUS_K2)); + return (C); } @@ -258,16 +247,16 @@ SUNAdaptController SUNAdaptController_ExpGus(SUNContext sunctx) * Function to set explicit Gustafsson parameters */ -int SUNAdaptController_SetParams_ExpGus(SUNAdaptController C, sunrealtype k1, - sunrealtype k2) +SUNErrCode SUNAdaptController_SetParams_ExpGus(SUNAdaptController C, + sunrealtype k1, sunrealtype k2) { - if (C == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } + SUNFunctionBegin(C->sunctx); SODERLIND_K1(C) = k1 + k2; SODERLIND_K2(C) = -k2; SODERLIND_K3(C) = SUN_RCONST(0.0); SODERLIND_K4(C) = SUN_RCONST(0.0); SODERLIND_K5(C) = SUN_RCONST(0.0); - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } /* ----------------------------------------------------------------- @@ -276,18 +265,15 @@ int SUNAdaptController_SetParams_ExpGus(SUNAdaptController C, sunrealtype k1, SUNAdaptController SUNAdaptController_ImpGus(SUNContext sunctx) { + SUNFunctionBegin(sunctx); + SUNAdaptController C; - int retval; - if (sunctx == NULL) { return NULL; } C = SUNAdaptController_Soderlind(sunctx); - if (C == NULL) { return NULL; } - retval = SUNAdaptController_SetParams_ImpGus(C, DEFAULT_IMPGUS_K1, - DEFAULT_IMPGUS_K2); - if (retval != SUNADAPTCONTROLLER_SUCCESS) - { - (void)SUNAdaptController_Destroy(C); - C = NULL; - } + SUNCheckLastErrNull(); + + SUNCheckCallNull(SUNAdaptController_SetParams_ImpGus(C, DEFAULT_IMPGUS_K1, + DEFAULT_IMPGUS_K2)); + return (C); } @@ -295,16 +281,16 @@ SUNAdaptController SUNAdaptController_ImpGus(SUNContext sunctx) * Function to set explicit Gustafsson parameters */ -int SUNAdaptController_SetParams_ImpGus(SUNAdaptController C, sunrealtype k1, - sunrealtype k2) +SUNErrCode SUNAdaptController_SetParams_ImpGus(SUNAdaptController C, + sunrealtype k1, sunrealtype k2) { - if (C == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } + SUNFunctionBegin(C->sunctx); SODERLIND_K1(C) = k1 + k2; SODERLIND_K2(C) = -k2; SODERLIND_K3(C) = SUN_RCONST(0.0); SODERLIND_K4(C) = SUN_RCONST(1.0); SODERLIND_K5(C) = SUN_RCONST(0.0); - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } /* ----------------------------------------------------------------- @@ -316,10 +302,14 @@ SUNAdaptController_Type SUNAdaptController_GetType_Soderlind(SUNAdaptController return SUN_ADAPTCONTROLLER_H; } -int SUNAdaptController_EstimateStep_Soderlind(SUNAdaptController C, - sunrealtype h, int p, - sunrealtype dsm, sunrealtype* hnew) +SUNErrCode SUNAdaptController_EstimateStep_Soderlind(SUNAdaptController C, + sunrealtype h, int p, + sunrealtype dsm, + sunrealtype* hnew) { + SUNFunctionBegin(C->sunctx); + SUNAssert(hnew, SUN_ERR_ARG_CORRUPT); + /* order parameter to use */ const int ord = p + 1; @@ -335,8 +325,6 @@ int SUNAdaptController_EstimateStep_Soderlind(SUNAdaptController C, const sunrealtype hrat = h / SODERLIND_HP(C); const sunrealtype hrat2 = SODERLIND_HP(C) / SODERLIND_HPP(C); - if (C == NULL || hnew == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } - /* compute estimated optimal time step size */ if (SODERLIND_FIRSTSTEPS(C) < 1) { *hnew = h * SUNRpowerR(e1, k1); } else if (SODERLIND_FIRSTSTEPS(C) < 2) @@ -350,35 +338,36 @@ int SUNAdaptController_EstimateStep_Soderlind(SUNAdaptController C, } /* return with success */ - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } -int SUNAdaptController_Reset_Soderlind(SUNAdaptController C) +SUNErrCode SUNAdaptController_Reset_Soderlind(SUNAdaptController C) { - if (C == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } + SUNFunctionBegin(C->sunctx); SODERLIND_EP(C) = SUN_RCONST(1.0); SODERLIND_EPP(C) = SUN_RCONST(1.0); SODERLIND_HP(C) = SUN_RCONST(1.0); SODERLIND_HPP(C) = SUN_RCONST(1.0); SODERLIND_FIRSTSTEPS(C) = 0; - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } -int SUNAdaptController_SetDefaults_Soderlind(SUNAdaptController C) +SUNErrCode SUNAdaptController_SetDefaults_Soderlind(SUNAdaptController C) { - if (C == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } + SUNFunctionBegin(C->sunctx); SODERLIND_K1(C) = DEFAULT_K1; SODERLIND_K2(C) = DEFAULT_K2; SODERLIND_K3(C) = DEFAULT_K3; SODERLIND_K4(C) = DEFAULT_K4; SODERLIND_K5(C) = DEFAULT_K5; SODERLIND_BIAS(C) = DEFAULT_BIAS; - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } -int SUNAdaptController_Write_Soderlind(SUNAdaptController C, FILE* fptr) +SUNErrCode SUNAdaptController_Write_Soderlind(SUNAdaptController C, FILE* fptr) { - if (C == NULL || fptr == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } + SUNFunctionBegin(C->sunctx); + SUNAssert(fptr, SUN_ERR_ARG_CORRUPT); fprintf(fptr, "Soderlind SUNAdaptController module:\n"); #if defined(SUNDIALS_EXTENDED_PRECISION) fprintf(fptr, " k1 = %32Lg\n", SODERLIND_K1(C)); @@ -404,40 +393,40 @@ int SUNAdaptController_Write_Soderlind(SUNAdaptController C, FILE* fptr) fprintf(fptr, " previous-previous step = %16g\n", SODERLIND_HPP(C)); #endif fprintf(fptr, " firststeps = %i\n", SODERLIND_FIRSTSTEPS(C)); - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } -int SUNAdaptController_SetErrorBias_Soderlind(SUNAdaptController C, - sunrealtype bias) +SUNErrCode SUNAdaptController_SetErrorBias_Soderlind(SUNAdaptController C, + sunrealtype bias) { - if (C == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } + SUNFunctionBegin(C->sunctx); + /* set allowed value, otherwise set default */ if (bias <= SUN_RCONST(0.0)) { SODERLIND_BIAS(C) = DEFAULT_BIAS; } else { SODERLIND_BIAS(C) = bias; } - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } -int SUNAdaptController_UpdateH_Soderlind(SUNAdaptController C, sunrealtype h, - sunrealtype dsm) +SUNErrCode SUNAdaptController_UpdateH_Soderlind(SUNAdaptController C, + sunrealtype h, sunrealtype dsm) { - if (C == NULL) { return SUNADAPTCONTROLLER_ILL_INPUT; } + SUNFunctionBegin(C->sunctx); SODERLIND_EPP(C) = SODERLIND_EP(C); SODERLIND_EP(C) = SODERLIND_BIAS(C) * dsm; SODERLIND_HPP(C) = SODERLIND_HP(C); SODERLIND_HP(C) = h; if (SODERLIND_FIRSTSTEPS(C) < 2) { SODERLIND_FIRSTSTEPS(C) += 1; } - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } -int SUNAdaptController_Space_Soderlind(SUNAdaptController C, long int* lenrw, - long int* leniw) +SUNErrCode SUNAdaptController_Space_Soderlind(SUNAdaptController C, + long int* lenrw, long int* leniw) { - if (C == NULL || lenrw == NULL || leniw == NULL) - { - return SUNADAPTCONTROLLER_ILL_INPUT; - } + SUNFunctionBegin(C->sunctx); + SUNAssert(lenrw, SUN_ERR_ARG_CORRUPT); + SUNAssert(leniw, SUN_ERR_ARG_CORRUPT); *lenrw = 10; *leniw = 1; - return SUNADAPTCONTROLLER_SUCCESS; + return SUN_SUCCESS; } diff --git a/src/sundials/fmod/fsundials_adaptcontroller_mod.f90 b/src/sundials/fmod/fsundials_adaptcontroller_mod.f90 index 0a77d1d87e..d940d37551 100644 --- a/src/sundials/fmod/fsundials_adaptcontroller_mod.f90 +++ b/src/sundials/fmod/fsundials_adaptcontroller_mod.f90 @@ -63,9 +63,6 @@ module fsundials_adaptcontroller_mod public :: FSUNAdaptController_SetErrorBias public :: FSUNAdaptController_UpdateH public :: FSUNAdaptController_Space - integer(C_INT), parameter, public :: SUNADAPTCONTROLLER_SUCCESS = 0_C_INT - integer(C_INT), parameter, public :: SUNADAPTCONTROLLER_ILL_INPUT = -1001_C_INT - integer(C_INT), parameter, public :: SUNADAPTCONTROLLER_USER_FCN_FAIL = -1003_C_INT ! WRAPPER DECLARATIONS interface diff --git a/src/sundials/fmod/fsundials_context_mod.f90 b/src/sundials/fmod/fsundials_context_mod.f90 index b0778ea9f9..c33c0bc2dd 100644 --- a/src/sundials/fmod/fsundials_context_mod.f90 +++ b/src/sundials/fmod/fsundials_context_mod.f90 @@ -39,6 +39,7 @@ module fsundials_context_mod enumerator :: SUN_ERR_MALLOC_FAIL enumerator :: SUN_ERR_DESTROY_FAIL enumerator :: SUN_ERR_NOT_IMPLEMENTED + enumerator :: SUN_ERR_USER_FCN_FAIL enumerator :: SUN_ERR_PROFILER_MAPFULL enumerator :: SUN_ERR_PROFILER_MAPGET enumerator :: SUN_ERR_PROFILER_MAPINSERT @@ -53,9 +54,9 @@ module fsundials_context_mod end enum public :: SUN_ERR_MINIMUM, SUN_ERR_ARG_CORRUPT, SUN_ERR_ARG_INCOMPATIBLE, SUN_ERR_ARG_OUTOFRANGE, SUN_ERR_ARG_WRONGTYPE, & SUN_ERR_ARG_DIMSMISMATCH, SUN_ERR_CORRUPT, SUN_ERR_FILE_OPEN, SUN_ERR_MEM_FAIL, SUN_ERR_MALLOC_FAIL, SUN_ERR_DESTROY_FAIL, & - SUN_ERR_NOT_IMPLEMENTED, SUN_ERR_PROFILER_MAPFULL, SUN_ERR_PROFILER_MAPGET, SUN_ERR_PROFILER_MAPINSERT, & - SUN_ERR_PROFILER_MAPKEYNOTFOUND, SUN_ERR_PROFILER_MAPSORT, SUN_ERR_SUNCTX_CORRUPT, SUN_ERR_MPI_FAIL, SUN_ERR_UNREACHABLE, & - SUN_ERR_UNKNOWN, SUN_ERR_MAXIMUM, SUN_SUCCESS + SUN_ERR_NOT_IMPLEMENTED, SUN_ERR_USER_FCN_FAIL, SUN_ERR_PROFILER_MAPFULL, SUN_ERR_PROFILER_MAPGET, & + SUN_ERR_PROFILER_MAPINSERT, SUN_ERR_PROFILER_MAPKEYNOTFOUND, SUN_ERR_PROFILER_MAPSORT, SUN_ERR_SUNCTX_CORRUPT, & + SUN_ERR_MPI_FAIL, SUN_ERR_UNREACHABLE, SUN_ERR_UNKNOWN, SUN_ERR_MAXIMUM, SUN_SUCCESS type, bind(C) :: SwigArrayWrapper type(C_PTR), public :: data = C_NULL_PTR integer(C_SIZE_T), public :: size = 0 diff --git a/src/sunmemory/cuda/sundials_cuda_memory.cu b/src/sunmemory/cuda/sundials_cuda_memory.cu index 388505f1c8..1d2a56b2e4 100644 --- a/src/sunmemory/cuda/sundials_cuda_memory.cu +++ b/src/sunmemory/cuda/sundials_cuda_memory.cu @@ -18,6 +18,8 @@ #include #include +#include "sundials/priv/sundials_errors_impl.h" +#include "sundials/sundials_errors.h" #include "sundials_cuda.h" #include "sundials_debug.h" @@ -47,10 +49,13 @@ typedef struct SUNMemoryHelper_Content_Cuda_ SUNMemoryHelper_Content_Cuda; SUNMemoryHelper SUNMemoryHelper_Cuda(SUNContext sunctx) { + SUNFunctionBegin(sunctx); + SUNMemoryHelper helper; /* Allocate the helper */ helper = SUNMemoryHelper_NewEmpty(sunctx); + SUNCheckLastErrNull(); /* Set the ops */ helper->ops->alloc = SUNMemoryHelper_Alloc_Cuda; @@ -64,6 +69,8 @@ SUNMemoryHelper SUNMemoryHelper_Cuda(SUNContext sunctx) /* Attach content */ helper->content = (SUNMemoryHelper_Content_Cuda*)malloc(sizeof(SUNMemoryHelper_Content_Cuda)); + SUNAssertNull(helper->content, SUN_ERR_MALLOC_FAIL); + SUNHELPER_CONTENT(helper)->num_allocations_host = 0; SUNHELPER_CONTENT(helper)->num_deallocations_host = 0; SUNHELPER_CONTENT(helper)->bytes_allocated_host = 0; @@ -86,15 +93,20 @@ SUNMemoryHelper SUNMemoryHelper_Cuda(SUNContext sunctx) SUNMemoryHelper SUNMemoryHelper_Clone_Cuda(SUNMemoryHelper helper) { + SUNFunctionBegin(helper->sunctx); SUNMemoryHelper hclone = SUNMemoryHelper_Cuda(helper->sunctx); + SUNCheckLastErrNull(); return hclone; } -int SUNMemoryHelper_Alloc_Cuda(SUNMemoryHelper helper, SUNMemory* memptr, - size_t mem_size, SUNMemoryType mem_type, - void* queue) +SUNErrCode SUNMemoryHelper_Alloc_Cuda(SUNMemoryHelper helper, SUNMemory* memptr, + size_t mem_size, SUNMemoryType mem_type, + void* queue) { + SUNFunctionBegin(helper->sunctx); + SUNMemory mem = SUNMemoryNewEmpty(helper->sunctx); + SUNCheckLastErr(); mem->ptr = NULL; mem->own = SUNTRUE; @@ -104,21 +116,12 @@ int SUNMemoryHelper_Alloc_Cuda(SUNMemoryHelper helper, SUNMemory* memptr, if (mem_type == SUNMEMTYPE_HOST) { mem->ptr = malloc(mem_size); - if (mem->ptr == NULL) - { - SUNDIALS_DEBUG_PRINT( - "ERROR in SUNMemoryHelper_Alloc_Cuda: malloc returned NULL\n"); - free(mem); - return (-1); - } - else - { - SUNHELPER_CONTENT(helper)->bytes_allocated_host += mem_size; - SUNHELPER_CONTENT(helper)->num_allocations_host++; - SUNHELPER_CONTENT(helper)->bytes_high_watermark_host = - SUNMAX(SUNHELPER_CONTENT(helper)->bytes_allocated_host, - SUNHELPER_CONTENT(helper)->bytes_high_watermark_host); - } + SUNAssert(mem->ptr, SUN_ERR_MALLOC_FAIL); + SUNHELPER_CONTENT(helper)->bytes_allocated_host += mem_size; + SUNHELPER_CONTENT(helper)->num_allocations_host++; + SUNHELPER_CONTENT(helper)->bytes_high_watermark_host = + SUNMAX(SUNHELPER_CONTENT(helper)->bytes_allocated_host, + SUNHELPER_CONTENT(helper)->bytes_high_watermark_host); } else if (mem_type == SUNMEMTYPE_PINNED) { @@ -127,7 +130,7 @@ int SUNMemoryHelper_Alloc_Cuda(SUNMemoryHelper helper, SUNMemory* memptr, SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Alloc_Cuda: cudaMallocHost failed\n"); free(mem); - return (-1); + return SUN_ERR_EXT_FAIL; } else { @@ -145,7 +148,7 @@ int SUNMemoryHelper_Alloc_Cuda(SUNMemoryHelper helper, SUNMemory* memptr, SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Alloc_Cuda: cudaMalloc failed\n"); free(mem); - return (-1); + return SUN_ERR_EXT_FAIL; } else { @@ -163,7 +166,7 @@ int SUNMemoryHelper_Alloc_Cuda(SUNMemoryHelper helper, SUNMemory* memptr, SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Alloc_Cuda: cudaMallocManaged failed\n"); free(mem); - return (-1); + return SUN_ERR_EXT_FAIL; } else { @@ -179,17 +182,17 @@ int SUNMemoryHelper_Alloc_Cuda(SUNMemoryHelper helper, SUNMemory* memptr, SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Alloc_Cuda: unknown memory type\n"); free(mem); - return (-1); + return SUN_ERR_ARG_OUTOFRANGE; } *memptr = mem; - return (0); + return SUN_SUCCESS; } -int SUNMemoryHelper_Dealloc_Cuda(SUNMemoryHelper helper, SUNMemory mem, - void* queue) +SUNErrCode SUNMemoryHelper_Dealloc_Cuda(SUNMemoryHelper helper, SUNMemory mem, + void* queue) { - if (mem == NULL) { return (0); } + if (mem == NULL) { return SUN_SUCCESS; } if (mem->ptr != NULL && mem->own) { @@ -208,7 +211,7 @@ int SUNMemoryHelper_Dealloc_Cuda(SUNMemoryHelper helper, SUNMemory mem, { SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Dealloc_Cuda: cudaFreeHost failed\n"); - return (-1); + return SUN_ERR_EXT_FAIL; } mem->ptr = NULL; } @@ -220,7 +223,7 @@ int SUNMemoryHelper_Dealloc_Cuda(SUNMemoryHelper helper, SUNMemory mem, { SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Dealloc_Cuda: cudaFree failed\n"); - return (-1); + return SUN_ERR_EXT_FAIL; } mem->ptr = NULL; } @@ -232,7 +235,7 @@ int SUNMemoryHelper_Dealloc_Cuda(SUNMemoryHelper helper, SUNMemory mem, { SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Dealloc_Cuda: cudaFree failed\n"); - return (-1); + return SUN_ERR_EXT_FAIL; } mem->ptr = NULL; } @@ -240,18 +243,19 @@ int SUNMemoryHelper_Dealloc_Cuda(SUNMemoryHelper helper, SUNMemory mem, { SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Dealloc_Cuda: unknown memory type\n"); - return (-1); + return SUN_ERR_EXT_FAIL; } } free(mem); - return (0); + return SUN_SUCCESS; } -int SUNMemoryHelper_Copy_Cuda(SUNMemoryHelper helper, SUNMemory dst, - SUNMemory src, size_t memory_size, void* queue) +SUNErrCode SUNMemoryHelper_Copy_Cuda(SUNMemoryHelper helper, SUNMemory dst, + SUNMemory src, size_t memory_size, + void* queue) { - int retval = 0; + int retval = SUN_SUCCESS; cudaError_t cuerr = cudaSuccess; switch (src->type) @@ -266,7 +270,7 @@ int SUNMemoryHelper_Copy_Cuda(SUNMemoryHelper helper, SUNMemory dst, { cuerr = cudaMemcpy(dst->ptr, src->ptr, memory_size, cudaMemcpyHostToDevice); } - if (!SUNDIALS_CUDA_VERIFY(cuerr)) { retval = -1; } + if (!SUNDIALS_CUDA_VERIFY(cuerr)) { retval = SUN_ERR_EXT_FAIL; } break; case SUNMEMTYPE_UVM: case SUNMEMTYPE_DEVICE: @@ -279,21 +283,22 @@ int SUNMemoryHelper_Copy_Cuda(SUNMemoryHelper helper, SUNMemory dst, cuerr = cudaMemcpy(dst->ptr, src->ptr, memory_size, cudaMemcpyDeviceToDevice); } - if (!SUNDIALS_CUDA_VERIFY(cuerr)) { retval = -1; } + if (!SUNDIALS_CUDA_VERIFY(cuerr)) { retval = SUN_ERR_EXT_FAIL; } break; default: SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_CopyAsync_Cuda: unknown memory type\n"); - retval = -1; + retval = SUN_ERR_OUTOFRANGE; } return (retval); } -int SUNMemoryHelper_CopyAsync_Cuda(SUNMemoryHelper helper, SUNMemory dst, - SUNMemory src, size_t memory_size, void* queue) +SUNErrCode SUNMemoryHelper_CopyAsync_Cuda(SUNMemoryHelper helper, SUNMemory dst, + SUNMemory src, size_t memory_size, + void* queue) { - int retval = 0; + int retval = SUN_SUCCESS; cudaError_t cuerr = cudaSuccess; cudaStream_t stream = 0; @@ -312,7 +317,7 @@ int SUNMemoryHelper_CopyAsync_Cuda(SUNMemoryHelper helper, SUNMemory dst, cuerr = cudaMemcpyAsync(dst->ptr, src->ptr, memory_size, cudaMemcpyHostToDevice, stream); } - if (!SUNDIALS_CUDA_VERIFY(cuerr)) { retval = -1; } + if (!SUNDIALS_CUDA_VERIFY(cuerr)) { retval = SUN_ERR_EXT_FAIL; } break; case SUNMEMTYPE_UVM: case SUNMEMTYPE_DEVICE: @@ -326,18 +331,18 @@ int SUNMemoryHelper_CopyAsync_Cuda(SUNMemoryHelper helper, SUNMemory dst, cuerr = cudaMemcpyAsync(dst->ptr, src->ptr, memory_size, cudaMemcpyDeviceToDevice, stream); } - if (!SUNDIALS_CUDA_VERIFY(cuerr)) { retval = -1; } + if (!SUNDIALS_CUDA_VERIFY(cuerr)) { retval = SUN_ERR_EXT_FAIL; } break; default: SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_CopyAsync_Cuda: unknown memory type\n"); - retval = -1; + retval = SUN_ERR_OUTOFRANGE; } return (retval); } -int SUNMemoryHelper_Destroy_Cuda(SUNMemoryHelper helper) +SUNErrCode SUNMemoryHelper_Destroy_Cuda(SUNMemoryHelper helper) { if (helper) { @@ -345,15 +350,15 @@ int SUNMemoryHelper_Destroy_Cuda(SUNMemoryHelper helper) if (helper->ops) { free(helper->ops); } free(helper); } - return 0; + return SUN_SUCCESS; } -int SUNMemoryHelper_GetAllocStats_Cuda(SUNMemoryHelper helper, - SUNMemoryType mem_type, - unsigned long* num_allocations, - unsigned long* num_deallocations, - size_t* bytes_allocated, - size_t* bytes_high_watermark) +SUNErrCode SUNMemoryHelper_GetAllocStats_Cuda(SUNMemoryHelper helper, + SUNMemoryType mem_type, + unsigned long* num_allocations, + unsigned long* num_deallocations, + size_t* bytes_allocated, + size_t* bytes_high_watermark) { if (mem_type == SUNMEMTYPE_HOST) { @@ -383,6 +388,6 @@ int SUNMemoryHelper_GetAllocStats_Cuda(SUNMemoryHelper helper, *bytes_allocated = SUNHELPER_CONTENT(helper)->bytes_allocated_uvm; *bytes_high_watermark = SUNHELPER_CONTENT(helper)->bytes_high_watermark_uvm; } - else { return -1; } - return 0; + else { return SUN_ERR_ARG_OUTOFRANGE; } + return SUN_SUCCESS; } diff --git a/src/sunmemory/hip/sundials_hip_memory.hip.cpp b/src/sunmemory/hip/sundials_hip_memory.hip.cpp index fa83c9af7e..a631891f69 100644 --- a/src/sunmemory/hip/sundials_hip_memory.hip.cpp +++ b/src/sunmemory/hip/sundials_hip_memory.hip.cpp @@ -18,6 +18,8 @@ #include #include +#include "sundials/priv/sundials_errors_impl.h" +#include "sundials/sundials_errors.h" #include "sundials_debug.h" #include "sundials_hip.h" @@ -47,10 +49,13 @@ typedef struct SUNMemoryHelper_Content_Hip_ SUNMemoryHelper_Content_Hip; SUNMemoryHelper SUNMemoryHelper_Hip(SUNContext sunctx) { + SUNFunctionBegin(sunctx); + SUNMemoryHelper helper; /* Allocate the helper */ helper = SUNMemoryHelper_NewEmpty(sunctx); + SUNCheckLastErrNull(); /* Set the ops */ helper->ops->alloc = SUNMemoryHelper_Alloc_Hip; @@ -64,6 +69,8 @@ SUNMemoryHelper SUNMemoryHelper_Hip(SUNContext sunctx) /* Attach content and ops */ helper->content = (SUNMemoryHelper_Content_Hip*)malloc(sizeof(SUNMemoryHelper_Content_Hip)); + SUNAssertNull(helper->content, SUN_ERR_MALLOC_FAIL); + SUNHELPER_CONTENT(helper)->num_allocations_host = 0; SUNHELPER_CONTENT(helper)->num_deallocations_host = 0; SUNHELPER_CONTENT(helper)->bytes_allocated_host = 0; @@ -86,15 +93,20 @@ SUNMemoryHelper SUNMemoryHelper_Hip(SUNContext sunctx) SUNMemoryHelper SUNMemoryHelper_Clone_Hip(SUNMemoryHelper helper) { + SUNFunctionBegin(helper->sunctx); SUNMemoryHelper hclone = SUNMemoryHelper_Hip(helper->sunctx); + SUNCheckLastErrNull(); return hclone; } -int SUNMemoryHelper_Alloc_Hip(SUNMemoryHelper helper, SUNMemory* memptr, - size_t mem_size, SUNMemoryType mem_type, - void* queue) +SUNErrCode SUNMemoryHelper_Alloc_Hip(SUNMemoryHelper helper, SUNMemory* memptr, + size_t mem_size, SUNMemoryType mem_type, + void* queue) { + SUNFunctionBegin(helper->sunctx); + SUNMemory mem = SUNMemoryNewEmpty(helper->sunctx); + SUNCheckLastErrNull(); mem->ptr = NULL; mem->own = SUNTRUE; @@ -104,21 +116,12 @@ int SUNMemoryHelper_Alloc_Hip(SUNMemoryHelper helper, SUNMemory* memptr, if (mem_type == SUNMEMTYPE_HOST) { mem->ptr = malloc(mem_size); - if (mem->ptr == NULL) - { - SUNDIALS_DEBUG_PRINT( - "ERROR in SUNMemoryHelper_Alloc_Hip: malloc returned NULL\n"); - free(mem); - return (-1); - } - else - { - SUNHELPER_CONTENT(helper)->bytes_allocated_host += mem_size; - SUNHELPER_CONTENT(helper)->num_allocations_host++; - SUNHELPER_CONTENT(helper)->bytes_high_watermark_host = - SUNMAX(SUNHELPER_CONTENT(helper)->bytes_allocated_host, - SUNHELPER_CONTENT(helper)->bytes_high_watermark_host); - } + SUNAssert(mem->ptr, SUN_ERR_MALLOC_FAIL); + SUNHELPER_CONTENT(helper)->bytes_allocated_host += mem_size; + SUNHELPER_CONTENT(helper)->num_allocations_host++; + SUNHELPER_CONTENT(helper)->bytes_high_watermark_host = + SUNMAX(SUNHELPER_CONTENT(helper)->bytes_allocated_host, + SUNHELPER_CONTENT(helper)->bytes_high_watermark_host); } else if (mem_type == SUNMEMTYPE_PINNED) { @@ -127,7 +130,7 @@ int SUNMemoryHelper_Alloc_Hip(SUNMemoryHelper helper, SUNMemory* memptr, SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Alloc_Hip: hipMallocHost failed\n"); free(mem); - return (-1); + return SUN_ERR_EXT_FAIL; } else { @@ -145,7 +148,7 @@ int SUNMemoryHelper_Alloc_Hip(SUNMemoryHelper helper, SUNMemory* memptr, SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Alloc_Hip: hipMalloc failed\n"); free(mem); - return (-1); + return SUN_ERR_EXT_FAIL; } else { @@ -163,7 +166,7 @@ int SUNMemoryHelper_Alloc_Hip(SUNMemoryHelper helper, SUNMemory* memptr, SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Alloc_Hip: hipMallocManaged failed\n"); free(mem); - return (-1); + return SUN_ERR_EXT_FAIL; } else { @@ -179,16 +182,17 @@ int SUNMemoryHelper_Alloc_Hip(SUNMemoryHelper helper, SUNMemory* memptr, SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Alloc_Hip: unknown memory type\n"); free(mem); - return (-1); + return SUN_ERR_OUTOFRANGE; } *memptr = mem; - return (0); + return SUN_SUCCESS; } -int SUNMemoryHelper_Dealloc_Hip(SUNMemoryHelper helper, SUNMemory mem, void* queue) +SUNErrCode SUNMemoryHelper_Dealloc_Hip(SUNMemoryHelper helper, SUNMemory mem, + void* queue) { - if (mem == NULL) { return (0); } + if (mem == NULL) { return SUN_SUCCESS; } if (mem->ptr != NULL && mem->own) { @@ -207,7 +211,7 @@ int SUNMemoryHelper_Dealloc_Hip(SUNMemoryHelper helper, SUNMemory mem, void* que { SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Dealloc_Hip: hipFreeHost failed\n"); - return (-1); + return SUN_ERR_EXT_FAIL; } mem->ptr = NULL; } @@ -219,7 +223,7 @@ int SUNMemoryHelper_Dealloc_Hip(SUNMemoryHelper helper, SUNMemory mem, void* que { SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Dealloc_Hip: hipFree failed\n"); - return (-1); + return SUN_ERR_EXT_FAIL; } mem->ptr = NULL; } @@ -231,7 +235,7 @@ int SUNMemoryHelper_Dealloc_Hip(SUNMemoryHelper helper, SUNMemory mem, void* que { SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Dealloc_Hip: hipFree failed\n"); - return (-1); + return SUN_ERR_EXT_FAIL; } mem->ptr = NULL; } @@ -239,18 +243,19 @@ int SUNMemoryHelper_Dealloc_Hip(SUNMemoryHelper helper, SUNMemory mem, void* que { SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Dealloc_Hip: unknown memory type\n"); - return (-1); + return SUN_ERR_OUTOFRANGE; } } free(mem); - return (0); + return SUN_SUCCESS; } -int SUNMemoryHelper_Copy_Hip(SUNMemoryHelper helper, SUNMemory dst, - SUNMemory src, size_t memory_size, void* queue) +SUNErrCode SUNMemoryHelper_Copy_Hip(SUNMemoryHelper helper, SUNMemory dst, + SUNMemory src, size_t memory_size, + void* queue) { - int retval = 0; + int retval = SUN_SUCCESS; hipError_t hiperr = hipSuccess; switch (src->type) @@ -265,7 +270,7 @@ int SUNMemoryHelper_Copy_Hip(SUNMemoryHelper helper, SUNMemory dst, { hiperr = hipMemcpy(dst->ptr, src->ptr, memory_size, hipMemcpyHostToDevice); } - if (!SUNDIALS_HIP_VERIFY(hiperr)) { retval = -1; } + if (!SUNDIALS_HIP_VERIFY(hiperr)) { retval = SUN_ERR_EXT_FAIL; } break; case SUNMEMTYPE_UVM: case SUNMEMTYPE_DEVICE: @@ -278,21 +283,22 @@ int SUNMemoryHelper_Copy_Hip(SUNMemoryHelper helper, SUNMemory dst, hiperr = hipMemcpy(dst->ptr, src->ptr, memory_size, hipMemcpyDeviceToDevice); } - if (!SUNDIALS_HIP_VERIFY(hiperr)) { retval = -1; } + if (!SUNDIALS_HIP_VERIFY(hiperr)) { retval = SUN_ERR_EXT_FAIL; } break; default: SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_CopyAsync_Hip: unknown memory type\n"); - retval = -1; + retval = SUN_ERR_OUTOFRANGE; } return (retval); } -int SUNMemoryHelper_CopyAsync_Hip(SUNMemoryHelper helper, SUNMemory dst, - SUNMemory src, size_t memory_size, void* queue) +SUNErrCode SUNMemoryHelper_CopyAsync_Hip(SUNMemoryHelper helper, SUNMemory dst, + SUNMemory src, size_t memory_size, + void* queue) { - int retval = 0; + int retval = SUN_SUCCESS; hipError_t hiperr = hipSuccess; hipStream_t stream = 0; @@ -311,7 +317,7 @@ int SUNMemoryHelper_CopyAsync_Hip(SUNMemoryHelper helper, SUNMemory dst, hiperr = hipMemcpyAsync(dst->ptr, src->ptr, memory_size, hipMemcpyHostToDevice, stream); } - if (!SUNDIALS_HIP_VERIFY(hiperr)) { retval = -1; } + if (!SUNDIALS_HIP_VERIFY(hiperr)) { retval = SUN_ERR_EXT_FAIL; } break; case SUNMEMTYPE_UVM: case SUNMEMTYPE_DEVICE: @@ -325,18 +331,18 @@ int SUNMemoryHelper_CopyAsync_Hip(SUNMemoryHelper helper, SUNMemory dst, hiperr = hipMemcpyAsync(dst->ptr, src->ptr, memory_size, hipMemcpyDeviceToDevice, stream); } - if (!SUNDIALS_HIP_VERIFY(hiperr)) { retval = -1; } + if (!SUNDIALS_HIP_VERIFY(hiperr)) { retval = SUN_ERR_EXT_FAIL; } break; default: SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_CopyAsync_Hip: unknown memory type\n"); - retval = -1; + retval = SUN_ERR_OUTOFRANGE; } return (retval); } -int SUNMemoryHelper_Destroy_Hip(SUNMemoryHelper helper) +SUNErrCode SUNMemoryHelper_Destroy_Hip(SUNMemoryHelper helper) { if (helper) { @@ -344,15 +350,15 @@ int SUNMemoryHelper_Destroy_Hip(SUNMemoryHelper helper) if (helper->ops) { free(helper->ops); } free(helper); } - return 0; + return SUN_SUCCESS; } -int SUNMemoryHelper_GetAllocStats_Hip(SUNMemoryHelper helper, - SUNMemoryType mem_type, - unsigned long* num_allocations, - unsigned long* num_deallocations, - size_t* bytes_allocated, - size_t* bytes_high_watermark) +SUNErrCode SUNMemoryHelper_GetAllocStats_Hip(SUNMemoryHelper helper, + SUNMemoryType mem_type, + unsigned long* num_allocations, + unsigned long* num_deallocations, + size_t* bytes_allocated, + size_t* bytes_high_watermark) { if (mem_type == SUNMEMTYPE_HOST) { @@ -382,6 +388,6 @@ int SUNMemoryHelper_GetAllocStats_Hip(SUNMemoryHelper helper, *bytes_allocated = SUNHELPER_CONTENT(helper)->bytes_allocated_uvm; *bytes_high_watermark = SUNHELPER_CONTENT(helper)->bytes_high_watermark_uvm; } - else { return -1; } - return 0; + else { return SUN_ERR_ARG_OUTOFRANGE; } + return SUN_SUCCESS; } diff --git a/src/sunmemory/sycl/sundials_sycl_memory.cpp b/src/sunmemory/sycl/sundials_sycl_memory.cpp index d3eb55766c..b3089199f5 100644 --- a/src/sunmemory/sycl/sundials_sycl_memory.cpp +++ b/src/sunmemory/sycl/sundials_sycl_memory.cpp @@ -18,6 +18,8 @@ #include #include +#include "sundials/priv/sundials_errors_impl.h" +#include "sundials/sundials_errors.h" #include "sundials_debug.h" struct SUNMemoryHelper_Content_Sycl_ @@ -46,14 +48,11 @@ typedef struct SUNMemoryHelper_Content_Sycl_ SUNMemoryHelper_Content_Sycl; SUNMemoryHelper SUNMemoryHelper_Sycl(SUNContext sunctx) { + SUNFunctionBegin(sunctx); + // Allocate the helper SUNMemoryHelper helper = SUNMemoryHelper_NewEmpty(sunctx); - if (!helper) - { - SUNDIALS_DEBUG_PRINT("ERROR in SUNMemoryHelper_Sycl: " - "SUNMemoryHelper_NewEmpty returned NULL\n"); - return NULL; - } + SUNCheckLastErrNull(); // Set the ops helper->ops->alloc = SUNMemoryHelper_Alloc_Sycl; @@ -67,6 +66,8 @@ SUNMemoryHelper SUNMemoryHelper_Sycl(SUNContext sunctx) // Attach content helper->content = (SUNMemoryHelper_Content_Sycl*)malloc(sizeof(SUNMemoryHelper_Content_Sycl)); + SUNAssertNull(helper->content, SUN_ERR_MALLOC_FAIL); + SUNHELPER_CONTENT(helper)->num_allocations_host = 0; SUNHELPER_CONTENT(helper)->num_deallocations_host = 0; SUNHELPER_CONTENT(helper)->bytes_allocated_host = 0; @@ -89,31 +90,25 @@ SUNMemoryHelper SUNMemoryHelper_Sycl(SUNContext sunctx) SUNMemoryHelper SUNMemoryHelper_Clone_Sycl(SUNMemoryHelper helper) { + SUNFunctionBegin(helper->sunctx); SUNMemoryHelper hclone = SUNMemoryHelper_Sycl(helper->sunctx); + SUNCheckLastErrNull(); return hclone; } -int SUNMemoryHelper_Alloc_Sycl(SUNMemoryHelper helper, SUNMemory* memptr, - size_t mem_size, SUNMemoryType mem_type, - void* queue) +SUNErrCode SUNMemoryHelper_Alloc_Sycl(SUNMemoryHelper helper, SUNMemory* memptr, + size_t mem_size, SUNMemoryType mem_type, + void* queue) { + SUNFunctionBegin(helper->sunctx); + // Check inputs - if (!queue) - { - SUNDIALS_DEBUG_PRINT( - "ERROR in SUNMemoryHelper_Alloc_Sycl: queue is NULL\n"); - return -1; - } + SUNAssert(queue, SUN_ERR_ARG_CORRUPT); ::sycl::queue* sycl_queue = static_cast<::sycl::queue*>(queue); // Allocate the memory struct SUNMemory mem = SUNMemoryNewEmpty(helper->sunctx); - if (!mem) - { - SUNDIALS_DEBUG_PRINT( - "ERROR in SUNMemoryHelper_Sycl: SUNMemoryNewEmpty returned NULL\n"); - return -1; - } + SUNCheckLastErr(); // Initialize the memory content mem->ptr = nullptr; @@ -130,7 +125,7 @@ int SUNMemoryHelper_Alloc_Sycl(SUNMemoryHelper helper, SUNMemory* memptr, SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Alloc_Sycl: malloc returned NULL\n"); free(mem); - return -1; + return SUN_ERR_EXT_FAIL; } else { @@ -149,7 +144,7 @@ int SUNMemoryHelper_Alloc_Sycl(SUNMemoryHelper helper, SUNMemory* memptr, SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Alloc_Sycl: malloc_host returned NULL\n"); free(mem); - return -1; + return SUN_ERR_EXT_FAIL; } else { @@ -168,7 +163,7 @@ int SUNMemoryHelper_Alloc_Sycl(SUNMemoryHelper helper, SUNMemory* memptr, SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Alloc_Sycl: malloc_device returned NULL\n"); free(mem); - return -1; + return SUN_ERR_EXT_FAIL; } else { @@ -187,7 +182,7 @@ int SUNMemoryHelper_Alloc_Sycl(SUNMemoryHelper helper, SUNMemory* memptr, SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Alloc_Sycl: malloc_shared returned NULL\n"); free(mem); - return -1; + return SUN_ERR_EXT_FAIL; } else { @@ -203,26 +198,23 @@ int SUNMemoryHelper_Alloc_Sycl(SUNMemoryHelper helper, SUNMemory* memptr, SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Alloc_Sycl: unknown memory type\n"); free(mem); - return -1; + return SUN_ERR_ARG_OUTOFRANGE; } *memptr = mem; - return 0; + return SUN_SUCCESS; } -int SUNMemoryHelper_Dealloc_Sycl(SUNMemoryHelper helper, SUNMemory mem, - void* queue) +SUNErrCode SUNMemoryHelper_Dealloc_Sycl(SUNMemoryHelper helper, SUNMemory mem, + void* queue) { - if (!mem) { return 0; } + SUNFunctionBegin(helper->sunctx); + + if (!mem) { return SUN_SUCCESS; } if (mem->ptr && mem->own) { - if (!queue) - { - SUNDIALS_DEBUG_PRINT( - "ERROR in SUNMemoryHelper_Dealloc_Sycl: queue is NULL\n"); - return -1; - } + SUNAssert(queue, SUN_ERR_ARG_CORRUPT); ::sycl::queue* sycl_queue = static_cast<::sycl::queue*>(queue); if (mem->type == SUNMEMTYPE_HOST) @@ -257,41 +249,36 @@ int SUNMemoryHelper_Dealloc_Sycl(SUNMemoryHelper helper, SUNMemory mem, { SUNDIALS_DEBUG_PRINT( "ERROR in SUNMemoryHelper_Dealloc_Sycl: unknown memory type\n"); - return -1; + return SUN_ERR_OUTOFRANGE; } } free(mem); - return 0; + return SUN_SUCCESS; } -int SUNMemoryHelper_Copy_Sycl(SUNMemoryHelper helper, SUNMemory dst, - SUNMemory src, size_t memory_size, void* queue) +SUNErrCode SUNMemoryHelper_Copy_Sycl(SUNMemoryHelper helper, SUNMemory dst, + SUNMemory src, size_t memory_size, + void* queue) { - if (!queue) - { - SUNDIALS_DEBUG_PRINT("ERROR in SUNMemoryHelper_Copy_Sycl: queue is NULL\n"); - return -1; - } + SUNFunctionBegin(helper->sunctx); + SUNAssert(queue, SUN_ERR_ARG_CORRUPT); ::sycl::queue* sycl_queue = static_cast<::sycl::queue*>(queue); if (SUNMemoryHelper_CopyAsync_Sycl(helper, dst, src, memory_size, queue)) { - return -1; + return SUN_ERR_EXT_FAIL; } sycl_queue->wait_and_throw(); - return 0; + return SUN_SUCCESS; } -int SUNMemoryHelper_CopyAsync_Sycl(SUNMemoryHelper helper, SUNMemory dst, - SUNMemory src, size_t memory_size, void* queue) +SUNErrCode SUNMemoryHelper_CopyAsync_Sycl(SUNMemoryHelper helper, SUNMemory dst, + SUNMemory src, size_t memory_size, + void* queue) { - if (!queue) - { - SUNDIALS_DEBUG_PRINT( - "ERROR in SUNMemoryHelper_CopyAsync_Sycl: queue is NULL\n"); - return -1; - } + SUNFunctionBegin(helper->sunctx); + SUNAssert(queue, SUN_ERR_ARG_CORRUPT); ::sycl::queue* sycl_queue = static_cast<::sycl::queue*>(queue); if (src->type == SUNMEMTYPE_HOST && dst->type == SUNMEMTYPE_HOST) @@ -299,10 +286,10 @@ int SUNMemoryHelper_CopyAsync_Sycl(SUNMemoryHelper helper, SUNMemory dst, memcpy(dst->ptr, src->ptr, memory_size); } else { sycl_queue->memcpy(dst->ptr, src->ptr, memory_size); } - return 0; + return SUN_SUCCESS; } -int SUNMemoryHelper_Destroy_Sycl(SUNMemoryHelper helper) +SUNErrCode SUNMemoryHelper_Destroy_Sycl(SUNMemoryHelper helper) { if (helper) { @@ -310,15 +297,15 @@ int SUNMemoryHelper_Destroy_Sycl(SUNMemoryHelper helper) if (helper->ops) { free(helper->ops); } free(helper); } - return 0; + return SUN_SUCCESS; } -int SUNMemoryHelper_GetAllocStats_Sycl(SUNMemoryHelper helper, - SUNMemoryType mem_type, - unsigned long* num_allocations, - unsigned long* num_deallocations, - size_t* bytes_allocated, - size_t* bytes_high_watermark) +SUNErrCode SUNMemoryHelper_GetAllocStats_Sycl(SUNMemoryHelper helper, + SUNMemoryType mem_type, + unsigned long* num_allocations, + unsigned long* num_deallocations, + size_t* bytes_allocated, + size_t* bytes_high_watermark) { if (mem_type == SUNMEMTYPE_HOST) { @@ -348,6 +335,6 @@ int SUNMemoryHelper_GetAllocStats_Sycl(SUNMemoryHelper helper, *bytes_allocated = SUNHELPER_CONTENT(helper)->bytes_allocated_uvm; *bytes_high_watermark = SUNHELPER_CONTENT(helper)->bytes_high_watermark_uvm; } - else { return -1; } - return 0; + else { return SUN_ERR_ARG_OUTOFRANGE; } + return SUN_SUCCESS; } diff --git a/src/sunmemory/system/sundials_system_memory.c b/src/sunmemory/system/sundials_system_memory.c index 1db579a438..9235f5a8bb 100644 --- a/src/sunmemory/system/sundials_system_memory.c +++ b/src/sunmemory/system/sundials_system_memory.c @@ -20,6 +20,9 @@ #include #include +#include "sundials/priv/sundials_errors_impl.h" +#include "sundials/sundials_errors.h" +#include "sundials/sundials_memory.h" #include "sundials_debug.h" struct SUNMemoryHelper_Content_Sys_ @@ -36,10 +39,13 @@ typedef struct SUNMemoryHelper_Content_Sys_ SUNMemoryHelper_Content_Sys; SUNMemoryHelper SUNMemoryHelper_Sys(SUNContext sunctx) { + SUNFunctionBegin(sunctx); + SUNMemoryHelper helper; /* Allocate the helper */ helper = SUNMemoryHelper_NewEmpty(sunctx); + SUNCheckLastErrNull(); /* Set the ops */ helper->ops->alloc = SUNMemoryHelper_Alloc_Sys; @@ -52,6 +58,8 @@ SUNMemoryHelper SUNMemoryHelper_Sys(SUNContext sunctx) /* Attach content and ops */ helper->content = (SUNMemoryHelper_Content_Sys*)malloc(sizeof(SUNMemoryHelper_Content_Sys)); + SUNAssertNull(helper->content, SUN_ERR_MALLOC_FAIL); + SUNHELPER_CONTENT(helper)->num_allocations = 0; SUNHELPER_CONTENT(helper)->num_deallocations = 0; SUNHELPER_CONTENT(helper)->bytes_allocated = 0; @@ -60,11 +68,16 @@ SUNMemoryHelper SUNMemoryHelper_Sys(SUNContext sunctx) return helper; } -int SUNMemoryHelper_Alloc_Sys(SUNMemoryHelper helper, SUNMemory* memptr, - size_t mem_size, SUNMemoryType mem_type, - void* queue) +SUNErrCode SUNMemoryHelper_Alloc_Sys(SUNMemoryHelper helper, SUNMemory* memptr, + size_t mem_size, SUNMemoryType mem_type, + void* queue) { + SUNFunctionBegin(helper->sunctx); + + SUNAssert(mem_type == SUNMEMTYPE_HOST, SUN_ERR_ARG_INCOMPATIBLE); + SUNMemory mem = SUNMemoryNewEmpty(helper->sunctx); + SUNCheckLastErr(); mem->ptr = NULL; mem->own = SUNTRUE; @@ -74,34 +87,26 @@ int SUNMemoryHelper_Alloc_Sys(SUNMemoryHelper helper, SUNMemory* memptr, if (mem_type == SUNMEMTYPE_HOST) { mem->ptr = malloc(mem_size); - if (mem->ptr == NULL) - { - SUNDIALS_DEBUG_PRINT( - "ERROR in SUNMemoryHelper_Alloc_Sys: malloc returned NULL\n"); - free(mem); - return (-1); - } + SUNAssert(mem->ptr, SUN_ERR_MALLOC_FAIL); SUNHELPER_CONTENT(helper)->bytes_allocated += mem_size; SUNHELPER_CONTENT(helper)->num_allocations++; SUNHELPER_CONTENT(helper)->bytes_high_watermark = SUNMAX(SUNHELPER_CONTENT(helper)->bytes_allocated, SUNHELPER_CONTENT(helper)->bytes_high_watermark); } - else - { - SUNDIALS_DEBUG_PRINT( - "ERROR in SUNMemoryHelper_Alloc_Sys: unsupported memory type\n"); - free(mem); - return (-1); - } *memptr = mem; - return (0); + return SUN_SUCCESS; } -int SUNMemoryHelper_Dealloc_Sys(SUNMemoryHelper helper, SUNMemory mem, void* queue) +SUNErrCode SUNMemoryHelper_Dealloc_Sys(SUNMemoryHelper helper, SUNMemory mem, + void* queue) { - if (mem == NULL) { return (0); } + SUNFunctionBegin(helper->sunctx); + + if (mem == NULL) { return SUN_SUCCESS; } + + SUNAssert(mem->type == SUNMEMTYPE_HOST, SUN_ERR_ARG_INCOMPATIBLE); if (mem->ptr != NULL && mem->own) { @@ -112,51 +117,47 @@ int SUNMemoryHelper_Dealloc_Sys(SUNMemoryHelper helper, SUNMemory mem, void* que free(mem->ptr); mem->ptr = NULL; } - else - { - SUNDIALS_DEBUG_PRINT( - "ERROR in SUNMemoryHelper_Dealloc_Sys: unsupported memory type\n"); - return (-1); - } } free(mem); - return (0); + return SUN_SUCCESS; } -int SUNMemoryHelper_Copy_Sys(SUNMemoryHelper helper, SUNMemory dst, - SUNMemory src, size_t memory_size, void* queue) +SUNErrCode SUNMemoryHelper_Copy_Sys(SUNMemoryHelper helper, SUNMemory dst, + SUNMemory src, size_t memory_size, + void* queue) { - int retval = 0; + SUNFunctionBegin(helper->sunctx); + SUNAssert(src->type == SUNMEMTYPE_HOST, SUN_ERR_ARG_INCOMPATIBLE); + SUNAssert(dst->type == SUNMEMTYPE_HOST, SUN_ERR_ARG_INCOMPATIBLE); memcpy(dst->ptr, src->ptr, memory_size); - return (retval); + return SUN_SUCCESS; } -int SUNMemoryHelper_GetAllocStats_Sys(SUNMemoryHelper helper, - SUNMemoryType mem_type, - unsigned long* num_allocations, - unsigned long* num_deallocations, - size_t* bytes_allocated, - size_t* bytes_high_watermark) +SUNErrCode SUNMemoryHelper_GetAllocStats_Sys(SUNMemoryHelper helper, + SUNMemoryType mem_type, + unsigned long* num_allocations, + unsigned long* num_deallocations, + size_t* bytes_allocated, + size_t* bytes_high_watermark) { - if (mem_type == SUNMEMTYPE_HOST) - { - *num_allocations = SUNHELPER_CONTENT(helper)->num_allocations; - *num_deallocations = SUNHELPER_CONTENT(helper)->num_deallocations; - *bytes_allocated = SUNHELPER_CONTENT(helper)->bytes_allocated; - *bytes_high_watermark = SUNHELPER_CONTENT(helper)->bytes_high_watermark; - } - else { return -1; } - return 0; + SUNFunctionBegin(helper->sunctx); + SUNAssert(mem_type == SUNMEMTYPE_HOST, SUN_ERR_ARG_INCOMPATIBLE); + *num_allocations = SUNHELPER_CONTENT(helper)->num_allocations; + *num_deallocations = SUNHELPER_CONTENT(helper)->num_deallocations; + *bytes_allocated = SUNHELPER_CONTENT(helper)->bytes_allocated; + *bytes_high_watermark = SUNHELPER_CONTENT(helper)->bytes_high_watermark; + return SUN_SUCCESS; } SUNMemoryHelper SUNMemoryHelper_Clone_Sys(SUNMemoryHelper helper) { SUNMemoryHelper hclone = SUNMemoryHelper_Sys(helper->sunctx); + SUNCheckLastErrNull(); return hclone; } -int SUNMemoryHelper_Destroy_Sys(SUNMemoryHelper helper) +SUNErrCode SUNMemoryHelper_Destroy_Sys(SUNMemoryHelper helper) { if (helper) { @@ -164,5 +165,5 @@ int SUNMemoryHelper_Destroy_Sys(SUNMemoryHelper helper) if (helper->ops) { free(helper->ops); } free(helper); } - return 0; + return SUN_SUCCESS; }