annotate src/fftw-3.3.8/genfft/dag.ml @ 82:d0c2a83c1364

Add FFTW 3.3.8 source, and a Linux build
author Chris Cannam
date Tue, 19 Nov 2019 14:52:55 +0000
parents
children
rev   line source
Chris@82 1 (*
Chris@82 2 * Copyright (c) 1997-1999 Massachusetts Institute of Technology
Chris@82 3 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@82 4 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@82 5 *
Chris@82 6 * This program is free software; you can redistribute it and/or modify
Chris@82 7 * it under the terms of the GNU General Public License as published by
Chris@82 8 * the Free Software Foundation; either version 2 of the License, or
Chris@82 9 * (at your option) any later version.
Chris@82 10 *
Chris@82 11 * This program is distributed in the hope that it will be useful,
Chris@82 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@82 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@82 14 * GNU General Public License for more details.
Chris@82 15 *
Chris@82 16 * You should have received a copy of the GNU General Public License
Chris@82 17 * along with this program; if not, write to the Free Software
Chris@82 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@82 19 *
Chris@82 20 *)
Chris@82 21
Chris@82 22 open Util
Chris@82 23
Chris@82 24 (* Here, we have functions to transform a sequence of assignments
Chris@82 25 (variable = expression) into a DAG (a directed, acyclic graph).
Chris@82 26 The nodes of the DAG are the assignments, and the edges indicate
Chris@82 27 dependencies. (The DAG is analyzed in the scheduler to find an
Chris@82 28 efficient ordering of the assignments.)
Chris@82 29
Chris@82 30 This file also contains utilities to manipulate the DAG in various
Chris@82 31 ways. *)
Chris@82 32
Chris@82 33 (********************************************
Chris@82 34 * Dag structure
Chris@82 35 ********************************************)
Chris@82 36 type color = RED | BLUE | BLACK | YELLOW
Chris@82 37
Chris@82 38 type dagnode =
Chris@82 39 { assigned: Variable.variable;
Chris@82 40 mutable expression: Expr.expr;
Chris@82 41 input_variables: Variable.variable list;
Chris@82 42 mutable successors: dagnode list;
Chris@82 43 mutable predecessors: dagnode list;
Chris@82 44 mutable label: int;
Chris@82 45 mutable color: color}
Chris@82 46
Chris@82 47 type dag = Dag of (dagnode list)
Chris@82 48
Chris@82 49 (* true if node uses v *)
Chris@82 50 let node_uses v node =
Chris@82 51 List.exists (Variable.same v) node.input_variables
Chris@82 52
Chris@82 53 (* true if assignment of v clobbers any input of node *)
Chris@82 54 let node_clobbers node v =
Chris@82 55 List.exists (Variable.same_location v) node.input_variables
Chris@82 56
Chris@82 57 (* true if nodeb depends on nodea *)
Chris@82 58 let depends_on nodea nodeb =
Chris@82 59 node_uses nodea.assigned nodeb ||
Chris@82 60 node_clobbers nodea nodeb.assigned
Chris@82 61
Chris@82 62 (* transform an assignment list into a dag *)
Chris@82 63 let makedag alist =
Chris@82 64 let dag = List.map
Chris@82 65 (fun assignment ->
Chris@82 66 let (v, x) = assignment in
Chris@82 67 { assigned = v;
Chris@82 68 expression = x;
Chris@82 69 input_variables = Expr.find_vars x;
Chris@82 70 successors = [];
Chris@82 71 predecessors = [];
Chris@82 72 label = 0;
Chris@82 73 color = BLACK })
Chris@82 74 alist
Chris@82 75 in begin
Chris@82 76 for_list dag (fun i ->
Chris@82 77 for_list dag (fun j ->
Chris@82 78 if depends_on i j then begin
Chris@82 79 i.successors <- j :: i.successors;
Chris@82 80 j.predecessors <- i :: j.predecessors;
Chris@82 81 end));
Chris@82 82 Dag dag;
Chris@82 83 end
Chris@82 84
Chris@82 85 let map f (Dag dag) = Dag (List.map f dag)
Chris@82 86 let for_all (Dag dag) f =
Chris@82 87 (* type system loophole *)
Chris@82 88 let make_unit _ = () in
Chris@82 89 make_unit (List.map f dag)
Chris@82 90 let to_list (Dag dag) = dag
Chris@82 91
Chris@82 92 let find_node f (Dag dag) = Util.find_elem f dag
Chris@82 93
Chris@82 94 (* breadth-first search *)
Chris@82 95 let rec bfs (Dag dag) node init_label =
Chris@82 96 let _ = node.label <- init_label in
Chris@82 97 let rec loop = function
Chris@82 98 [] -> ()
Chris@82 99 | node :: rest ->
Chris@82 100 let neighbors = node.predecessors @ node.successors in
Chris@82 101 let m = min_list (List.map (fun node -> node.label) neighbors) in
Chris@82 102 if (node.label > m + 1) then begin
Chris@82 103 node.label <- m + 1;
Chris@82 104 loop (rest @ neighbors);
Chris@82 105 end else
Chris@82 106 loop rest
Chris@82 107 in let neighbors = node.predecessors @ node.successors in
Chris@82 108 loop neighbors
Chris@82 109