Skip to content

Commit

Permalink
#74 Add iterations diff calculation function
Browse files Browse the repository at this point in the history
  • Loading branch information
hleb-albau committed Nov 16, 2018
1 parent 1f31d9e commit 8aebf0f
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions cosmos/poc/cuda/rank.cu
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#include <stdint.h>
#include <stdio.h>
#include <thrust/transform.h>
#include <thrust/transform_reduce.h>
#include <thrust/device_vector.h>
#include <thrust/execution_policy.h>
#include <thrust/functional.h>
#include "types.h"

const double DUMP_FACTOR = 0.85;
const double TOLERANCE = 1e-3;

/******************************************/
/* CELL STRUCT LEADING TO ARRAY OF STRUCT */
/******************************************/
/*******************************************/
/* REPRESENTS INCOMING LINK WITH IT WEIGHT */
/*******************************************/
typedef struct {
/* Index of opposite cid in cids array */
uint64_t fromIndex;
Expand Down Expand Up @@ -50,6 +55,39 @@ void run_rank_iteration(
}


/*****************************************************/
/* KERNEL: DOUBLE ABS FUNCTOR */
/*****************************************************/
/* Return absolute value for double */
/*****************************************************/
struct absolute_value {
__device__ double operator()(const double &x) const {
return x < 0.0 ? -x : x;
}
};


/*****************************************************/
/* KERNEL: FINDS MAXIMUM RANKS DIFFERENCE */
/*****************************************************/
/* Finds maximum rank difference for single element */
/* */
/*****************************************************/
double find_max_ranks_diff(double *prevRank, double *newRank, uint64_t rankSize) {

thrust::device_vector<double> ranksDiff(rankSize);
thrust::device_ptr<double> newRankBegin(newRank);
thrust::device_ptr<double> prevRankBegin(prevRank);
thrust::device_ptr<double> prevRankEnd(prevRank + rankSize);
thrust::transform(thrust::device,
prevRankBegin, prevRankEnd, newRankBegin, ranksDiff.begin(), thrust::minus<double>()
);

return thrust::transform_reduce(thrust::device,
ranksDiff.begin(), ranksDiff.end(), absolute_value(), 0.0, thrust::maximum<double>()
);
}

extern "C" {

void calculate_rank(
Expand All @@ -58,6 +96,8 @@ extern "C" {
cid_link *inLinks, cid_link *outLinks /* Incoming and Outgoing cids links */
) {

printf("Cuda !!!!!!!!!!!!!!!!!!\n");

double *prevRank, *rank;
cudaMalloc(&rank, cidsSize*sizeof(double));
cudaMalloc(&prevRank, cidsSize*sizeof(double));
Expand All @@ -69,6 +109,7 @@ extern "C" {
//change = calculateChange(prevrank, rank)
//prevrank = rank
steps++;
return;
}

cudaFree(rank);
Expand Down

0 comments on commit 8aebf0f

Please sign in to comment.