Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New implementations of kernel 2 and 3 for graph500 #388

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 64 additions & 15 deletions benchmarks/graph500seq/dune
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
; kernel1 and kronecker have been replaced with new, more optimized
; implementations.
(executable (name kronecker) (modules kronecker))
(library (name kernel1Old) (modules kernel1Old))
(executable (name kernel2) (modules kernel2) (libraries kernel1Old))
(executable (name kernel3) (modules kernel3) (libraries kernel1Old))

;;;;; Newer implementations ;;;;;

(library
(name generateSeq)
(modules generateSeq)
(libraries graphTypes)
(libraries graphTypes fileHandler)
)

(library
(name fileHandler)
(modules fileHandler)
)

(executable
(name gen)
(modules gen)
(libraries unix generateSeq)
(libraries unix generateSeq fileHandler)
)

(library
(name sparseGraphSeq)
(modules sparseGraphSeq)
(libraries graphTypes)
;(preprocess; (pps ppx_inline_test ppx_assert))
;(inline_tests)
)

(library
Expand All @@ -31,14 +30,64 @@
(libraries generateSeq sparseGraphSeq unix)
)

(library
(name kernel2Seq)
(modules kernel2Seq)
(libraries generateSeq sparseGraphSeq unix)
;(preprocess; (pps ppx_inline_test ppx_assert))
;(inline_tests)
)

(library
(name kernel3Seq)
(modules kernel3Seq)
(libraries graphTypes generateSeq sparseGraphSeq unix)
;(preprocess; (pps ppx_inline_test ppx_assert))
;(inline_tests)
)

(executable
(name sampleSearchKeys)
(modules sampleSearchKeys)
(libraries graphTypes generateSeq sparseGraphSeq unix)
)

(executable
(name kernel1_run)
(modules kernel1_run)
(libraries graphTypes generateSeq kernel1Seq unix)
(libraries sparseGraphSeq graphTypes fileHandler kernel1Seq unix)
)

(alias
(name buildbench)
(deps kronecker.exe kernel2.exe kernel3.exe
gen.exe kernel1_run.exe)
(executable
(name kernel2_run)
(modules kernel2_run)
(modes byte exe)
(libraries sparseGraphSeq graphTypes fileHandler kernel2Seq unix)
)

(executable
(name kernel2_run_multicore)
(modules kernel2_run_multicore)
(modes byte exe)
(libraries domainslib sparseGraphSeq graphTypes fileHandler kernel2Seq unix)
)

(executable
(name kernel3_run)
(modules kernel3_run)
(modes byte exe)
(libraries sparseGraphSeq graphTypes fileHandler kernel3Seq unix)
)

(executable
(name kernel3_run_multicore)
(modules kernel3_run_multicore)
(modes byte exe)
(libraries domainslib sparseGraphSeq graphTypes fileHandler kernel3Seq unix)
)

;(alias
; (name buildbench)
; (deps kronecker.exe kernel2.exe kernel3.exe
; gen.exe kernel1_run.exe)
;)
10 changes: 10 additions & 0 deletions benchmarks/graph500seq/fileHandler.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let to_file ~filename (data : 'a ) =
let out = open_out filename in
Marshal.to_channel out data [];
close_out out

let from_file filename =
let in_ = open_in filename in
let res : 'a = Marshal.from_channel in_ in
close_in in_;
res
3 changes: 3 additions & 0 deletions benchmarks/graph500seq/fileHandler.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
val to_file : filename:string -> 'a -> unit

val from_file : string -> 'a

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the Marshal usage came from previous work, but it is rather unsafe as it stands, because it doesn't (and cannot) check that the value returned is of the correct type. You could make it safer in a number of ways. I'd perhaps recommend finding a library that offers a type safe version of marshaling/serialization/pickling.

4 changes: 2 additions & 2 deletions benchmarks/graph500seq/gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ let () =
Printf.eprintf "Must provide graph file argument.\n"; exit 1
end;
let scale = !scale and edge_factor = !edge_factor in
Printf.printf "Generating edge list...\n%!";
Printf.printf "Generating edge list of scale %d...\n%!" scale;
let t0 = Unix.gettimeofday () in
let edges = GenerateSeq.go ~scale ~edge_factor in
let t1 = Unix.gettimeofday () in
Printf.printf "Generated. Time: %f s.\n" (t1 -. t0);
GenerateSeq.to_file ~filename:!filename edges;
FileHandler.to_file ~filename:!filename edges;
13 changes: 13 additions & 0 deletions benchmarks/graph500seq/genAndKernel1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

SCALE=$1

gen () { ./_build/default/gen.exe -scale $SCALE edges.data; }

kernel1 () { ./_build/default/kernel1_run.exe edges.data -o sparse.data; }

getSamples () { ./_build/default/sampleSearchKeys.exe sparse.data -o samples.data; }

gen && kernel1 && getSamples


3 changes: 3 additions & 0 deletions benchmarks/graph500seq/generateSamples.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let _ =
let samples = Array.init nsamples (fun _ -> SparseGraphSeq.get_sample graph) in
FileHandler.to_file ~filename:!filename samples
13 changes: 1 addition & 12 deletions benchmarks/graph500seq/generateSeq.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,5 @@ let kronecker ~scale ~edge_factor : (vertex * vertex * weight) array =
let go ~scale ~edge_factor =
kronecker ~scale ~edge_factor

let to_file ~filename (edges : edge array) =
let out = open_out filename in
Marshal.to_channel out edges [];
close_out out

let from_file filename =
let in_ = open_in filename in
let res : edge array = Marshal.from_channel in_ in
close_in in_;
res

let generate_to_file ~scale ~edge_factor ~filename =
go ~scale ~edge_factor |> to_file ~filename
go ~scale ~edge_factor |> FileHandler.to_file ~filename
2 changes: 0 additions & 2 deletions benchmarks/graph500seq/generateSeq.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
open GraphTypes

val go : scale:int -> edge_factor:int -> edge array
val to_file : filename:string -> edge array -> unit
val from_file : string -> edge array
val generate_to_file : scale:int -> edge_factor:int -> filename:string -> unit
3 changes: 3 additions & 0 deletions benchmarks/graph500seq/graphTypes.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type vertex = int
type weight = float
type edge = vertex * vertex * weight
113 changes: 0 additions & 113 deletions benchmarks/graph500seq/kernel1Old.ml

This file was deleted.

21 changes: 13 additions & 8 deletions benchmarks/graph500seq/kernel1_run.ml
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
let filename = ref ""
let usage_msg = "kernel1Seq_run.exe <edge_list_input_file> -o <sparse_graph_output_file>"
let edge_list_input_filename = ref ""
let sparse_graph_output_filename = ref ""

let speclist = [("-o", Arg.Set_string sparse_graph_output_filename, "Set output file name")]

let () =
Random.self_init ();
Arg.parse [] (fun s -> filename := s)
"kernel1Par.exe EDGE_LIST_FILE";
if !filename = "" then begin
Printf.eprintf "Must provide graph file argument.\n"; exit 1
Arg.parse speclist (fun s -> edge_list_input_filename := s) usage_msg;
if !edge_list_input_filename = "" then begin
Printf.eprintf "Must provide edge list input file argument.\n"; exit 1
end;
Printf.printf "Reading edge list from %s...\n%!" !filename;
Printf.printf "Reading edge list from %s...\n%!" !edge_list_input_filename;
let t0 = Unix.gettimeofday () in
let edges = GenerateSeq.from_file !filename in
let edges = FileHandler.from_file !edge_list_input_filename in
let t1 = Unix.gettimeofday () in
Printf.printf "Done. Time: %f s.\nBuilding sparse representation...\n%!" (t1 -. t0);
let t0 = Unix.gettimeofday () in
ignore @@ Sys.opaque_identity @@ Kernel1Seq.kernel1 edges;
let sparse_graph = Kernel1Seq.kernel1 edges in
let t1 = Unix.gettimeofday () in
Printf.printf "Done. Time: %f\n" (t1 -. t0);
FileHandler.to_file ~filename:!sparse_graph_output_filename sparse_graph;

Loading