annotate fft/fftw/fftw-3.3.4/genfft/dag.ml @ 40:223f770b5341 kissfft-double tip

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