def cc_push_topo(graph: Graph, property_name): print("Executing Push algo\n") num_nodes = graph.num_nodes() timer = StatTimer("CC: Property Graph Numba: " + property_name) timer.start() # Stores the component id assignment comp_current = np.empty((num_nodes, ), dtype=np.uint32) comp_old = np.empty((num_nodes, ), dtype=np.uint32) # Initialize do_all( range(num_nodes), initialize_cc_push_operator(graph, comp_current, comp_old), steal=True, loop_name="initialize_cc_push", ) # Execute while component ids are updated changed = ReduceLogicalOr() changed.update(True) while changed.reduce(): changed.reset() do_all( range(num_nodes), cc_push_topo_operator(graph, changed, comp_current, comp_old), steal=True, loop_name="cc_push_topo", ) timer.stop() # Add the component assignment as a new property to the property graph graph.add_node_property(pyarrow.table({property_name: comp_current}))
def bfs_sync_pg(graph: Graph, source, property_name): next_level_number = 0 curr_level = InsertBag[np.uint64]() next_level = InsertBag[np.uint64]() timer = StatTimer("BFS Property Graph Numba: " + property_name) timer.start() distance = np.empty((graph.num_nodes(), ), dtype=np.uint32) initialize(graph, source, distance) next_level.push(source) while not next_level.empty(): curr_level.swap(next_level) next_level.clear() next_level_number += 1 do_all( curr_level, bfs_sync_operator_pg(graph, next_level, next_level_number, distance), steal=True, loop_name="bfs_sync_pg", ) timer.stop() graph.add_node_property(pyarrow.table({property_name: distance}))
def main(): import argparse import katana.local katana.local.initialize() parser = argparse.ArgumentParser() parser.add_argument("--baseNode", type=int, default=0) parser.add_argument("--reportNode", type=int, default=1) parser.add_argument("--propertyName", type=str, default="NewProperty") parser.add_argument("--threads", "-t", type=int, default=1) parser.add_argument("input", type=str) args = parser.parse_args() print("Using threads:", set_active_threads(args.threads)) g = Graph(args.input) timer = StatTimer("Jaccard (Property Graph) Numba") timer.start() jaccard(g, args.baseNode, args.propertyName) timer.stop() del timer print("Node {}: {}".format(args.reportNode, g.get_node_property(args.propertyName)[args.reportNode]))
def kcore_async(graph: Graph, k_core_num, property_name): num_nodes = graph.num_nodes() initial_worklist = InsertBag[np.uint64]() current_degree = NUMAArray[np.uint64](num_nodes, AllocationPolicy.INTERLEAVED) timer = StatTimer("Kcore: Property Graph Numba: " + property_name) timer.start() # Initialize do_all( range(num_nodes), compute_degree_count_operator(graph, current_degree.as_numpy()), steal=True, ) # Setup initial worklist do_all( range(num_nodes), setup_initial_worklist_operator(initial_worklist, current_degree.as_numpy(), k_core_num), steal=True, ) # Compute k-core for_each( initial_worklist, compute_async_kcore_operator(graph, current_degree.as_numpy(), k_core_num), steal=True, disable_conflict_detection=True, ) timer.stop() # Add the ranks as a new property to the property graph graph.add_node_property(pyarrow.table({property_name: current_degree}))
def bind(self, args, unbound_argument_types): arg_types = tuple(typeof(v) for v in args) with StatTimer("Compilation", self.__qualname__): inst = self._generate(arg_types, unbound_argument_types) env = PointerPair() env_ptr = ctypes.addressof(env) env_struct = inst.Environment(*args) inst.store_struct(env_struct, env_ptr) return Closure( inst.wrapper, env, self._return_type, unbound_argument_types, captured=(env_struct, args), name=self.__name__, qualname=self.__qualname__, )
def pagerank_pull_sync_residual(graph: Graph, maxIterations, tolerance, property_name): num_nodes = graph.num_nodes() rank = NUMAArray[float](num_nodes, AllocationPolicy.INTERLEAVED) nout = NUMAArray[np.uint64](num_nodes, AllocationPolicy.INTERLEAVED) delta = NUMAArray[float](num_nodes, AllocationPolicy.INTERLEAVED) residual = NUMAArray[float](num_nodes, AllocationPolicy.INTERLEAVED) # Initialize do_all( range(num_nodes), initialize_residual_operator(rank.as_numpy(), nout.as_numpy(), delta.as_numpy(), residual.as_numpy(),), steal=True, loop_name="initialize_pagerank_pull_residual", ) # Compute out-degree for each node do_all( range(num_nodes), compute_out_deg_operator(graph, nout.as_numpy()), steal=True, loop_name="Compute_out_degree", ) print("Out-degree of 0: ", nout[0]) changed = ReduceOr(True) iterations = 0 timer = StatTimer("Pagerank: Property Graph Numba: " + property_name) timer.start() while iterations < maxIterations and changed.reduce(): print("Iter: ", iterations, "\n") changed.reset() iterations += 1 do_all( range(num_nodes), compute_pagerank_pull_delta_operator( rank.as_numpy(), nout.as_numpy(), delta.as_numpy(), residual.as_numpy(), tolerance, changed, ), steal=True, loop_name="pagerank_delta", ) do_all( range(num_nodes), compute_pagerank_pull_residual_operator(graph, delta.as_numpy(), residual.as_numpy()), steal=True, loop_name="pagerank", ) timer.stop() # Add the ranks as a new property to the property graph graph.add_node_property(pyarrow.table({property_name: rank}))
def sssp(graph: Graph, source, length_property, shift, property_name): dists = create_distance_array(graph, source, length_property) # Define the struct type here so it can depend on the type of the weight property UpdateRequest = np.dtype([("src", np.uint32), ("dist", dists.dtype)]) init_bag = InsertBag[UpdateRequest]() init_bag.push((source, 0)) t = StatTimer("Total SSSP") t.start() for_each( init_bag, sssp_operator(graph, dists, graph.get_edge_property(length_property)), worklist=OrderedByIntegerMetric(obim_indexer(shift)), disable_conflict_detection=True, loop_name="SSSP", ) t.stop() print("Elapsed time: ", t.get(), "milliseconds.") graph.add_node_property(pyarrow.table({property_name: dists}))
import atexit import ctypes from functools import wraps import llvmlite.ir from numba import types, typeof, njit from numba.experimental import jitclass from numba.extending import lower_builtin from numba.extending import type_callable from katana.numba_support.galois_compiler import OperatorCompiler, cfunc from katana.timer import StatTimer PointerPair = ctypes.c_void_p * 2 _compilation_timer = StatTimer("Compilation", "Katana-Python") atexit.register(_compilation_timer.finalize) class Closure: """ A closure containing a native function pointer and the environment needed to invoke it. These closures are used by galois to specify operators. """ __slots__ = [ "_function", "_userdata", "return_type", "unbound_argument_types", "_captured",