summaryrefslogtreecommitdiff
path: root/SpMV/support
diff options
context:
space:
mode:
authorBirte Kristina Friesel <birte.friesel@uos.de>2025-05-23 16:28:17 +0200
committerBirte Kristina Friesel <birte.friesel@uos.de>2025-05-23 16:28:35 +0200
commitfa6c70a44fc56cc50370e57c460dd61e8f127b51 (patch)
tree91269761966dccea80a2931542db5a3648f66e18 /SpMV/support
parent2e3a43c12df8115fc859248adb14b87e08becb77 (diff)
SpMV: Add AspectC++ support
Diffstat (limited to 'SpMV/support')
-rw-r--r--SpMV/support/common.h24
-rw-r--r--SpMV/support/matrix.h138
-rw-r--r--SpMV/support/params.h51
-rw-r--r--SpMV/support/timer.h30
-rw-r--r--SpMV/support/utils.h10
5 files changed, 0 insertions, 253 deletions
diff --git a/SpMV/support/common.h b/SpMV/support/common.h
deleted file mode 100644
index 6118814..0000000
--- a/SpMV/support/common.h
+++ /dev/null
@@ -1,24 +0,0 @@
-
-/* Common data structures between host and DPUs */
-
-#ifndef _COMMON_H_
-#define _COMMON_H_
-
-#define ROUND_UP_TO_MULTIPLE_OF_2(x) ((((x) + 1)/2)*2)
-#define ROUND_UP_TO_MULTIPLE_OF_8(x) ((((x) + 7)/8)*8)
-
-struct DPUParams {
- uint32_t dpuNumRows; /* Number of rows assigned to the DPU */
- uint32_t dpuRowPtrsOffset; /* Offset of the row pointers */
- uint32_t dpuRowPtrs_m;
- uint32_t dpuNonzeros_m;
- uint32_t dpuInVector_m;
- uint32_t dpuOutVector_m;
-};
-
-struct Nonzero {
- uint32_t col;
- float value;
-};
-
-#endif
diff --git a/SpMV/support/matrix.h b/SpMV/support/matrix.h
deleted file mode 100644
index ce8745e..0000000
--- a/SpMV/support/matrix.h
+++ /dev/null
@@ -1,138 +0,0 @@
-
-#ifndef _MATRIX_H_
-#define _MATRIX_H_
-
-#include <assert.h>
-#include <stdio.h>
-
-#include "common.h"
-#include "utils.h"
-
-struct COOMatrix {
- uint32_t numRows;
- uint32_t numCols;
- uint32_t numNonzeros;
- uint32_t *rowIdxs;
- struct Nonzero *nonzeros;
-};
-
-struct CSRMatrix {
- uint32_t numRows;
- uint32_t numCols;
- uint32_t numNonzeros;
- uint32_t *rowPtrs;
- struct Nonzero *nonzeros;
-};
-
-static struct COOMatrix readCOOMatrix(const char *fileName)
-{
-
- struct COOMatrix cooMatrix;
-
- // Initialize fields
- FILE *fp = fopen(fileName, "r");
- assert(fscanf(fp, "%u", &cooMatrix.numRows));
- if (cooMatrix.numRows % 2 == 1) {
- PRINT_WARNING
- ("Reading matrix %s: number of rows must be even. Padding with an extra row.",
- fileName);
- cooMatrix.numRows++;
- }
- assert(fscanf(fp, "%u", &cooMatrix.numCols));
- assert(fscanf(fp, "%u", &cooMatrix.numNonzeros));
- cooMatrix.rowIdxs =
- (uint32_t *)
- malloc(ROUND_UP_TO_MULTIPLE_OF_8
- (cooMatrix.numNonzeros * sizeof(uint32_t)));
- cooMatrix.nonzeros =
- (struct Nonzero *)
- malloc(ROUND_UP_TO_MULTIPLE_OF_8
- (cooMatrix.numNonzeros * sizeof(struct Nonzero)));
-
- // Read the nonzeros
- for (uint32_t i = 0; i < cooMatrix.numNonzeros; ++i) {
- uint32_t rowIdx;
- assert(fscanf(fp, "%u", &rowIdx));
- cooMatrix.rowIdxs[i] = rowIdx - 1; // File format indexes begin at 1
- uint32_t colIdx;
- assert(fscanf(fp, "%u", &colIdx));
- cooMatrix.nonzeros[i].col = colIdx - 1; // File format indexes begin at 1
- cooMatrix.nonzeros[i].value = 1.0f;
- }
-
- return cooMatrix;
-
-}
-
-static void freeCOOMatrix(struct COOMatrix cooMatrix)
-{
- free(cooMatrix.rowIdxs);
- free(cooMatrix.nonzeros);
-}
-
-static struct CSRMatrix coo2csr(struct COOMatrix cooMatrix)
-{
-
- struct CSRMatrix csrMatrix;
-
- // Initialize fields
- csrMatrix.numRows = cooMatrix.numRows;
- csrMatrix.numCols = cooMatrix.numCols;
- csrMatrix.numNonzeros = cooMatrix.numNonzeros;
- csrMatrix.rowPtrs =
- (uint32_t *)
- malloc(ROUND_UP_TO_MULTIPLE_OF_8
- ((csrMatrix.numRows + 1) * sizeof(uint32_t)));
- csrMatrix.nonzeros =
- (struct Nonzero *)
- malloc(ROUND_UP_TO_MULTIPLE_OF_8
- (csrMatrix.numNonzeros * sizeof(struct Nonzero)));
-
- // Histogram rowIdxs
- memset(csrMatrix.rowPtrs, 0,
- (csrMatrix.numRows + 1) * sizeof(uint32_t));
- for (uint32_t i = 0; i < cooMatrix.numNonzeros; ++i) {
- uint32_t rowIdx = cooMatrix.rowIdxs[i];
- csrMatrix.rowPtrs[rowIdx]++;
- }
-
- // Prefix sum rowPtrs
- uint32_t sumBeforeNextRow = 0;
- for (uint32_t rowIdx = 0; rowIdx < csrMatrix.numRows; ++rowIdx) {
- uint32_t sumBeforeRow = sumBeforeNextRow;
- sumBeforeNextRow += csrMatrix.rowPtrs[rowIdx];
- csrMatrix.rowPtrs[rowIdx] = sumBeforeRow;
- }
- csrMatrix.rowPtrs[csrMatrix.numRows] = sumBeforeNextRow;
-
- // Bin the nonzeros
- for (uint32_t i = 0; i < cooMatrix.numNonzeros; ++i) {
- uint32_t rowIdx = cooMatrix.rowIdxs[i];
- uint32_t nnzIdx = csrMatrix.rowPtrs[rowIdx]++;
- csrMatrix.nonzeros[nnzIdx] = cooMatrix.nonzeros[i];
- }
-
- // Restore rowPtrs
- for (uint32_t rowIdx = csrMatrix.numRows - 1; rowIdx > 0; --rowIdx) {
- csrMatrix.rowPtrs[rowIdx] = csrMatrix.rowPtrs[rowIdx - 1];
- }
- csrMatrix.rowPtrs[0] = 0;
-
- return csrMatrix;
-
-}
-
-static void freeCSRMatrix(struct CSRMatrix csrMatrix)
-{
- free(csrMatrix.rowPtrs);
- free(csrMatrix.nonzeros);
-}
-
-static void initVector(float *vec, uint32_t size)
-{
- for (uint32_t i = 0; i < size; ++i) {
- vec[i] = 1.0f;
- }
-}
-
-#endif
diff --git a/SpMV/support/params.h b/SpMV/support/params.h
deleted file mode 100644
index bf60e79..0000000
--- a/SpMV/support/params.h
+++ /dev/null
@@ -1,51 +0,0 @@
-
-#ifndef _PARAMS_H_
-#define _PARAMS_H_
-
-#include "common.h"
-#include "utils.h"
-
-static void usage()
-{
- PRINT("\nUsage: ./program [options]"
- "\n"
- "\nBenchmark-specific options:"
- "\n -f <F> input matrix file name (default=data/bcsstk30.mtx)"
- "\n"
- "\nGeneral options:"
- "\n -v <V> verbosity" "\n -h help" "\n\n");
-}
-
-typedef struct Params {
- const char *fileName;
- unsigned int verbosity;
-} Params;
-
-static struct Params input_params(int argc, char **argv)
-{
- struct Params p;
- p.fileName = "data/bcsstk30.mtx";
- p.verbosity = 1;
- int opt;
- while ((opt = getopt(argc, argv, "f:v:h")) >= 0) {
- switch (opt) {
- case 'f':
- p.fileName = optarg;
- break;
- case 'v':
- p.verbosity = atoi(optarg);
- break;
- case 'h':
- usage();
- exit(0);
- default:
- PRINT_ERROR("Unrecognized option!");
- usage();
- exit(0);
- }
- }
-
- return p;
-}
-
-#endif
diff --git a/SpMV/support/timer.h b/SpMV/support/timer.h
deleted file mode 100644
index 7367b11..0000000
--- a/SpMV/support/timer.h
+++ /dev/null
@@ -1,30 +0,0 @@
-
-#ifndef _TIMER_H_
-#define _TIMER_H_
-
-#include <stdio.h>
-#include <sys/time.h>
-
-typedef struct Timer {
- struct timeval startTime;
- struct timeval endTime;
-} Timer;
-
-static void startTimer(Timer *timer)
-{
- gettimeofday(&(timer->startTime), NULL);
-}
-
-static void stopTimer(Timer *timer)
-{
- gettimeofday(&(timer->endTime), NULL);
-}
-
-static double getElapsedTime(Timer timer)
-{
- return ((double)((timer.endTime.tv_sec - timer.startTime.tv_sec)
- + (timer.endTime.tv_usec -
- timer.startTime.tv_usec) / 1.0e6));
-}
-
-#endif
diff --git a/SpMV/support/utils.h b/SpMV/support/utils.h
deleted file mode 100644
index ccd8fbd..0000000
--- a/SpMV/support/utils.h
+++ /dev/null
@@ -1,10 +0,0 @@
-
-#ifndef _UTILS_H_
-#define _UTILS_H_
-
-#define PRINT_ERROR(fmt, ...) fprintf(stderr, "\033[0;31mERROR:\033[0m " fmt "\n", ##__VA_ARGS__)
-#define PRINT_WARNING(fmt, ...) fprintf(stderr, "\033[0;35mWARNING:\033[0m " fmt "\n", ##__VA_ARGS__)
-#define PRINT_INFO(cond, fmt, ...) if(cond) printf("\033[0;32mINFO:\033[0m " fmt "\n", ##__VA_ARGS__);
-#define PRINT(fmt, ...) printf(fmt "\n", ##__VA_ARGS__)
-
-#endif