Skip to content

Commit

Permalink
Refactor reduction implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
thilinarmtb committed Oct 4, 2023
1 parent 40294a0 commit 686c694
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 43 deletions.
4 changes: 0 additions & 4 deletions docs/internal-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ Memory Management Functions and Macros

Reductions and Related Functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. doxygengroup:: nomp_reduction_ops
:project: libnomp
:content-only:

.. doxygengroup:: nomp_reduction_utils
:project: libnomp
:content-only:
Expand Down
57 changes: 51 additions & 6 deletions include/nomp-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ typedef struct {
void *ptr;
} nomp_arg_t;

/**
* @defgroup nomp_reduction_utils Reduction utilities
*
* @brief Utilities used to perform reduction operations.
*/

/**
* @ingroup nomp_reduction_utils
*
* @brief Enum for different reduction operations.
*/
typedef enum {
NOMP_SUM = 0, /*!< Sum reduction. */
NOMP_PROD = 1 /*!< Multiplication reduction.*/
} nomp_reduction_op_t;

/**
* @ingroup nomp_internal_types
*
Expand All @@ -103,7 +119,11 @@ typedef struct {
*/
CVecBasic *sym_global, *sym_local;
/**
* Map of variable names and their values use to evaluate
* Flag used to determine if the grid size should be evaluated or not.
*/
int eval_grid;
/**
* Map of variable names and their values used to evaluate
* the kernel launch parameters.
*/
CMapBasicBasic *map;
Expand All @@ -112,12 +132,29 @@ typedef struct {
* input changes).
*/
size_t global[3], local[3], gws[3];
// Boolean flag to determine if the grid size should be evaluated or not.
int eval_grid;
// Pointer to keep track of backend specific data.
/**
* Pointer to keep track of backend specific data for the active backend.
*/
void *bptr;
// Reduction related metadata.
int redn_idx, redn_op, redn_type, redn_size;
/**
* Index of the deduction argument if one exists.
*/
int redn_idx;
/**
* Reduction operation to be performed.
*/
nomp_reduction_op_t redn_op;
/**
* Type of the reduction variable.
*/
nomp_type_t redn_type;
/**
* Size of the reduction variable given by sizeof().
*/
int redn_size;
/**
* Pointer to the reduction variable.
*/
void *redn_ptr;
} nomp_prog_t;

Expand Down Expand Up @@ -234,6 +271,14 @@ int cuda_init(nomp_backend_t *backend, int platform, int device);

int hip_init(nomp_backend_t *backend, int platform, int device);

/**
* @ingroup nomp_reduction_utils
*
* @brief Perform residual host side reductions.
*/
int nomp_host_side_reduction(nomp_backend_t *bnd, nomp_prog_t *prg,
nomp_mem_t *m);

#ifdef __cplusplus
}
#endif
Expand Down
31 changes: 0 additions & 31 deletions include/nomp-reduction.h

This file was deleted.

1 change: 0 additions & 1 deletion src/nomp.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "nomp-aux.h"
#include "nomp-impl.h"
#include "nomp-loopy.h"
#include "nomp-reduction.h"

static nomp_backend_t nomp;
static int initialized = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/reduction.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "nomp-reduction.h"
#include "nomp-impl.h"

#define NOMP_DO_SUM(a, b) (a) += (b)
#define NOMP_DO_PROD(a, b) (a) *= (b)
Expand Down

0 comments on commit 686c694

Please sign in to comment.