-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
489 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
all: | ||
g++ -std=c++11 truss_decomposition.cc truss_decomposition_host.cc -o td | ||
|
||
syn: | ||
vivado_hls -f run_td_hls.tcl | ||
|
||
clean: | ||
rm -rf td |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
open_project -reset td_hls | ||
set_top truss_decomposition | ||
add_files truss_decomposition.cc | ||
add_files -tb truss_decomposition_host.cc | ||
|
||
open_solution -reset "solution1" | ||
set_part {xc7z020clg400-1} | ||
create_clock -period 10 | ||
|
||
# csim_design | ||
|
||
csynth_design | ||
export_design -format ip_catalog -version "0.002" | ||
|
||
exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#define HLS | ||
|
||
#ifndef HLS | ||
#include "truss_decomposition.h" | ||
#endif | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <assert.h> | ||
|
||
|
||
#define LOCAL_BUF_SIZE 8192 | ||
|
||
#ifndef HLS | ||
int truss_decomposition(int *edge_tc, | ||
int *triangles, | ||
int *triangle_offsets, | ||
int *progress, | ||
int num_edges) | ||
#else | ||
int truss_decomposition(volatile int *edge_tc, | ||
volatile int *triangles, | ||
volatile int *triangle_offsets, | ||
volatile int *progress, | ||
int num_edges) | ||
#endif | ||
{ | ||
#ifdef HLS | ||
#pragma HLS INTERFACE m_axi port=edge_tc depth=32 offset=slave bundle=EDGE_TC | ||
#pragma HLS INTERFACE m_axi port=triangles depth=32 offset=slave bundle=TRIANGLES | ||
#pragma HLS INTERFACE m_axi port=triangle_offsets depth=32 offset=slave bundle=TRI_OFFSETS | ||
#pragma HLS INTERFACE m_axi port=progress depth=32 offset=slave bundle=PROGRESS | ||
#pragma HLS INTERFACE s_axilite register port=num_edges | ||
#pragma HLS INTERFACE s_axilite register port=return | ||
#endif | ||
int num_edges_left = 0; | ||
bool has_new_deletes = true; | ||
int num_new_deletes = 0; | ||
|
||
int local_buf_1[LOCAL_BUF_SIZE]; | ||
int local_buf_2[LOCAL_BUF_SIZE]; | ||
int local_buf_3[LOCAL_BUF_SIZE]; | ||
|
||
int prev_buf_1 = 0; | ||
int prev_buf_2 = 0; | ||
int prev_buf_3 = 0; | ||
|
||
unsigned int k = 0; | ||
while (1) | ||
{ | ||
if (!has_new_deletes) | ||
{ | ||
k++; | ||
progress[0] = k; | ||
#ifndef HLS | ||
std::cout << "k = " << k << std::endl; | ||
#endif | ||
} | ||
|
||
num_edges_left = 0; | ||
has_new_deletes = false; | ||
num_new_deletes = 0; | ||
|
||
for (int i = 1; i <= num_edges; i++) // edge idx starts from 1 | ||
{ | ||
int num_triangles = edge_tc[i]; | ||
if ((num_triangles < k) && (num_triangles != 0)) | ||
{ | ||
edge_tc[i] = 0; | ||
has_new_deletes = true; | ||
num_new_deletes++; | ||
int triangle_list_start = triangle_offsets[i-1]; | ||
int triangle_list_len = triangle_offsets[i] - triangle_list_start; | ||
|
||
if (i != prev_buf_1) | ||
{ | ||
memcpy(local_buf_1, (const int*)&(triangles[triangle_list_start]), triangle_list_len*sizeof(int)); | ||
prev_buf_1 = i; | ||
} | ||
|
||
for (int triangle_idx = 0; triangle_idx < triangle_list_len; triangle_idx+=2) | ||
{ | ||
int affected_edge_a = local_buf_1[triangle_idx]; | ||
int affected_edge_b = local_buf_1[triangle_idx+1]; | ||
if (affected_edge_a != 0) | ||
{ | ||
int affected_edge_a_start = triangle_offsets[affected_edge_a-1]; | ||
int affected_edge_b_start = triangle_offsets[affected_edge_b-1]; | ||
int affected_edge_a_len = triangle_offsets[affected_edge_a] - affected_edge_a_start; | ||
int affected_edge_b_len = triangle_offsets[affected_edge_b] - affected_edge_b_start; | ||
|
||
if (affected_edge_a != prev_buf_2) | ||
{ | ||
memcpy(local_buf_2, (const int*)&(triangles[affected_edge_a_start]), affected_edge_a_len*sizeof(int)); | ||
prev_buf_2 = affected_edge_a; | ||
} | ||
if (affected_edge_b != prev_buf_3) | ||
{ | ||
memcpy(local_buf_3, (const int*)&(triangles[affected_edge_b_start]), affected_edge_b_len*sizeof(int)); | ||
prev_buf_3 = affected_edge_b; | ||
} | ||
|
||
for (int affected_idx = 0; affected_idx < affected_edge_a_len; affected_idx+=2) | ||
{ | ||
int tmp_candidate_a = local_buf_2[affected_idx]; | ||
int tmp_candidate_b = local_buf_2[affected_idx+1]; | ||
if ((tmp_candidate_a == i) || (tmp_candidate_b == i)) | ||
{ | ||
triangles[affected_edge_a_start+affected_idx] = 0; | ||
triangles[affected_edge_a_start+affected_idx+1] = 0; | ||
edge_tc[affected_edge_a]--; | ||
break; | ||
} | ||
} | ||
|
||
for (int affected_idx = 0; affected_idx < affected_edge_b_len; affected_idx+=2) | ||
{ | ||
int tmp_candidate_a = local_buf_3[affected_idx]; | ||
int tmp_candidate_b = local_buf_3[affected_idx+1]; | ||
if ((tmp_candidate_a == i) || (tmp_candidate_b == i)) | ||
{ | ||
triangles[affected_edge_b_start+affected_idx] = 0; | ||
triangles[affected_edge_b_start+affected_idx+1] = 0; | ||
edge_tc[affected_edge_b]--; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
if (num_triangles != 0) | ||
num_edges_left++; | ||
} | ||
} | ||
|
||
if (num_edges_left == 0) | ||
break; | ||
} | ||
|
||
return k+1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef _TRUSS_DECOMPOSITION_H_ | ||
#define _TRUSS_DECOMPOSITION_H_ | ||
|
||
/*#define HLS*/ | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
#include <sstream> | ||
#include <vector> | ||
#include <cassert> | ||
/*#include <string>*/ | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
const unsigned int BUF_SIZE = 4096; | ||
const unsigned int hash_key_bitwidth = 20; | ||
const unsigned int hash_table_len = 1 << hash_key_bitwidth; | ||
const unsigned int max_num_elems = 8; | ||
|
||
|
||
void read_graph_td(const char *filename, | ||
std::vector<int> &edge_list, | ||
std::vector<int> &neighbor_list, | ||
std::vector<int> &offset_list); | ||
|
||
#ifndef HLS | ||
int truss_decomposition(int *edge_tc, | ||
int *triangles, | ||
int *triangle_offsets, | ||
int *progress, | ||
int num_edges); | ||
#else | ||
int truss_decomposition(volatile int *edge_tc, | ||
volatile int *triangles, | ||
volatile int *triangle_offsets, | ||
volatile int *progress, | ||
int num_edges) | ||
#endif | ||
|
||
#endif /* _TRUSS_DECOMPOSITION_H_ */ |
Oops, something went wrong.