<commit_before>#include <stdlib.h>
#include <iostream>
#include <string.h>
#include "xil_cache.h"
#include "SparseMatrix.h"
#include "SoftwareSpMV.h"
#include "malloc_aligned.h"

using namespace std;

unsigned int matrixMetaBase = 0x08000100;
unsigned int accBase = 0x40000000;
unsigned int resBase = 0x43c00000;

// use compile-time defines to decide which type of HW SpMV to use
#if defined(HWSPMV_BUFFERALL)
	#include "HardwareSpMV.h"
	#define HWSPMV	HardwareSPMV
	static const char * hwSpMVIDString = "BufferAll";
#elif defined(HWSPMV_BUFFERNONE)
	#include "HardwareSpMVBufferNone.h"
	#define HWSPMV HardwareSpMVBufferNone
	static const char * hwSpMVIDString = "BufferNone";
#endif

int main(int argc, char *argv[]) {
  Xil_DCacheDisable();

  cout << "SpMVAccel-" << hwSpMVIDString << endl;
  cout << "=====================================" << endl;

  SparseMatrix * A = SparseMatrix::fromMemory(matrixMetaBase);

  A->printSummary();

  SpMVData *x = (SpMVData *) malloc_aligned(64, sizeof(SpMVData)*A->getCols());
  SpMVData *y = (SpMVData *) malloc_aligned(64, sizeof(SpMVData)*A->getRows());

  for(SpMVIndex i = 0; i < A->getCols(); i++) { x[i] = (SpMVData) 1; }
  for(SpMVIndex i = 0; i < A->getRows(); i++) { y[i] = (SpMVData) 0; }

  SpMV * spmv = new HWSPMV(accBase, resBase, A, x, y);
  SoftwareSpMV check(A);

  spmv->exec();
  check.exec();

  SpMVData * goldenY = check.getY();
  int res = memcmp(goldenY, y, sizeof(SpMVData)*A->getRows());

  cout << "Memcmp result = " << res << endl;

  if(res != 0) {
	  unsigned int diffs = 0;
	  for(SpMVIndex i = 0; i < A->getRows(); i++) {
		  if(y[i] != goldenY[i]) diffs++;
	  }
	  cout << "A total of " << diffs << " result elements are different." << endl;
  }<commit_msg>software: ensure that we use the same input vec. for both hw and sw<commit_after>#include <stdlib.h>
#include <iostream>
#include <string.h>
#include "xil_cache.h"
#include "SparseMatrix.h"
#include "SoftwareSpMV.h"
#include "malloc_aligned.h"

using namespace std;

unsigned int matrixMetaBase = 0x08000100;
unsigned int accBase = 0x40000000;
unsigned int resBase = 0x43c00000;

// use compile-time defines to decide which type of HW SpMV to use
#if defined(HWSPMV_BUFFERALL)
	#include "HardwareSpMV.h"
	#define HWSPMV	HardwareSPMV
	static const char * hwSpMVIDString = "BufferAll";
#elif defined(HWSPMV_BUFFERNONE)
	#include "HardwareSpMVBufferNone.h"
	#define HWSPMV HardwareSpMVBufferNone
	static const char * hwSpMVIDString = "BufferNone";
#endif

int main(int argc, char *argv[]) {
  Xil_DCacheDisable();

  cout << "SpMVAccel-" << hwSpMVIDString << endl;
  cout << "=====================================" << endl;

  SparseMatrix * A = SparseMatrix::fromMemory(matrixMetaBase);

  A->printSummary();

  SpMVData *x = (SpMVData *) malloc_aligned(64, sizeof(SpMVData)*A->getCols());
  SpMVData *y = (SpMVData *) malloc_aligned(64, sizeof(SpMVData)*A->getRows());

  for(SpMVIndex i = 0; i < A->getCols(); i++) { x[i] = (SpMVData) 1; }
  for(SpMVIndex i = 0; i < A->getRows(); i++) { y[i] = (SpMVData) 0; }

  SpMV * spmv = new HWSPMV(accBase, resBase, A, x, y);
  SoftwareSpMV check(A, x);

  spmv->exec();
  check.exec();

  SpMVData * goldenY = check.getY();
  int res = memcmp(goldenY, y, sizeof(SpMVData)*A->getRows());

  cout << "Memcmp result = " << res << endl;

  if(res != 0) {
	  unsigned int diffs = 0;
	  for(SpMVIndex i = 0; i < A->getRows(); i++) {
		  if(y[i] != goldenY[i]) diffs++;
	  }
	  cout << "A total of " << diffs << " result elements are different." << endl;
  }
{'fraction_non_alphanumeric': 0.17767072825162936, 'fraction_numerical': 0.020969113063190707, 'mean_word_length': 4.550314465408805, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '575633', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1290, 'n_words': 334}