From 381fa26aac478dcb1da4ea53b8f6de4bb9531be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Mon, 2 Oct 2023 12:58:45 +0200 Subject: [PATCH] add hashfunction for checksum calculation --- CMakeLists.txt | 5 +++++ matrix.hpp | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a68522..9610a75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,13 @@ cmake_minimum_required(VERSION 3.25) +set(CMAKE_CXX_STANDARD 17) + project(sycl_example) find_package(AdaptiveCpp REQUIRED) +find_library(LIB_XXHASH xxhash) + add_executable(sycl_comp sycl_comp.cpp) add_sycl_to_target(TARGET sycl_comp) +target_link_libraries(sycl_comp PRIVATE ${LIB_XXHASH}) diff --git a/matrix.hpp b/matrix.hpp index 3887d4b..d0d321a 100644 --- a/matrix.hpp +++ b/matrix.hpp @@ -7,6 +7,8 @@ #include #include +#include + template struct Matrix { std::uint32_t rows; std::uint32_t cols; @@ -40,6 +42,10 @@ template struct Matrix { return data[row_i * cols + col_j]; } + const T &operator()(std::uint32_t row_i, std::uint32_t col_j) const { + return data[row_i * cols + col_j]; + } + Matrix &operator=(const Matrix &mat) { this->rows = mat.rows; this->cols = mat.cols; @@ -58,7 +64,10 @@ template struct Matrix { return transposed; } - T sum() const { return std::accumulate(data.begin(), data.end(), 0); } + XXH32_hash_t chksum() const { + constexpr XXH32_hash_t HASH_SEED = 42; + return XXH32(this->data.data(), data.size(), HASH_SEED); + } }; template std::ostream &operator<<(std::ostream &os, Matrix &mat) {