comparison fft/fftw/fftw-3.3.4/genfft/gen_notw.ml @ 19:26056e866c29

Add FFTW to comparison table
author Chris Cannam
date Tue, 06 Oct 2015 13:08:39 +0100
parents
children
comparison
equal deleted inserted replaced
18:8db794ca3e0b 19:26056e866c29
1 (*
2 * Copyright (c) 1997-1999 Massachusetts Institute of Technology
3 * Copyright (c) 2003, 2007-14 Matteo Frigo
4 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 *)
21
22 open Util
23 open Genutil
24 open C
25
26
27 let usage = "Usage: " ^ Sys.argv.(0) ^ " -n <number>"
28
29 let uistride = ref Stride_variable
30 let uostride = ref Stride_variable
31 let uivstride = ref Stride_variable
32 let uovstride = ref Stride_variable
33
34 let speclist = [
35 "-with-istride",
36 Arg.String(fun x -> uistride := arg_to_stride x),
37 " specialize for given input stride";
38
39 "-with-ostride",
40 Arg.String(fun x -> uostride := arg_to_stride x),
41 " specialize for given output stride";
42
43 "-with-ivstride",
44 Arg.String(fun x -> uivstride := arg_to_stride x),
45 " specialize for given input vector stride";
46
47 "-with-ovstride",
48 Arg.String(fun x -> uovstride := arg_to_stride x),
49 " specialize for given output vector stride"
50 ]
51
52 let nonstandard_optimizer list_of_buddy_stores dag =
53 let sched = standard_scheduler dag in
54 let annot = Annotate.annotate list_of_buddy_stores sched in
55 let _ = dump_asched annot in
56 annot
57
58 let generate n =
59 let riarray = "ri"
60 and iiarray = "ii"
61 and roarray = "ro"
62 and ioarray = "io"
63 and istride = "is"
64 and ostride = "os"
65 and i = "i"
66 and v = "v"
67 in
68
69 let sign = !Genutil.sign
70 and name = !Magic.codelet_name
71 and byvl x = choose_simd x (ctimes (CVar "(2 * VL)", x)) in
72 let ename = expand_name name in
73
74 let vistride = either_stride (!uistride) (C.SVar istride)
75 and vostride = either_stride (!uostride) (C.SVar ostride)
76 in
77
78 let sovs = stride_to_string "ovs" !uovstride in
79 let sivs = stride_to_string "ivs" !uivstride in
80
81 let locations = unique_array_c n in
82 let input =
83 locative_array_c n
84 (C.array_subscript riarray vistride)
85 (C.array_subscript iiarray vistride)
86 locations sivs in
87 let output = Fft.dft sign n (load_array_c n input) in
88 let oloc =
89 locative_array_c n
90 (C.array_subscript roarray vostride)
91 (C.array_subscript ioarray vostride)
92 locations sovs in
93 let list_of_buddy_stores =
94 let k = !Simdmagic.store_multiple in
95 if (k > 1) then
96 if (n mod k == 0) then
97 List.append
98 (List.map
99 (fun i -> List.map (fun j -> (fst (oloc (k * i + j)))) (iota k))
100 (iota (n / k)))
101 (List.map
102 (fun i -> List.map (fun j -> (snd (oloc (k * i + j)))) (iota k))
103 (iota (n / k)))
104 else failwith "invalid n for -store-multiple"
105 else []
106 in
107
108 let odag = store_array_c n oloc output in
109 let annot = nonstandard_optimizer list_of_buddy_stores odag in
110
111 let body = Block (
112 [Decl ("INT", i)],
113 [For (Expr_assign (CVar i, CVar v),
114 Binop (" > ", CVar i, Integer 0),
115 list_to_comma
116 [Expr_assign (CVar i, CPlus [CVar i; CUminus (byvl (Integer 1))]);
117 Expr_assign (CVar riarray, CPlus [CVar riarray;
118 byvl (CVar sivs)]);
119 Expr_assign (CVar iiarray, CPlus [CVar iiarray;
120 byvl (CVar sivs)]);
121 Expr_assign (CVar roarray, CPlus [CVar roarray;
122 byvl (CVar sovs)]);
123 Expr_assign (CVar ioarray, CPlus [CVar ioarray;
124 byvl (CVar sovs)]);
125 make_volatile_stride (4*n) (CVar istride);
126 make_volatile_stride (4*n) (CVar ostride)
127 ],
128 Asch annot)
129 ])
130 in
131
132 let tree =
133 Fcn ((if !Magic.standalone then "void" else "static void"), ename,
134 ([Decl (C.constrealtypep, riarray);
135 Decl (C.constrealtypep, iiarray);
136 Decl (C.realtypep, roarray);
137 Decl (C.realtypep, ioarray);
138 Decl (C.stridetype, istride);
139 Decl (C.stridetype, ostride);
140 Decl ("INT", v);
141 Decl ("INT", "ivs");
142 Decl ("INT", "ovs")]),
143 finalize_fcn body)
144
145 in let desc =
146 Printf.sprintf
147 "static const kdft_desc desc = { %d, %s, %s, &GENUS, %s, %s, %s, %s };\n"
148 n (stringify name) (flops_of tree)
149 (stride_to_solverparm !uistride) (stride_to_solverparm !uostride)
150 (choose_simd "0" (stride_to_solverparm !uivstride))
151 (choose_simd "0" (stride_to_solverparm !uovstride))
152
153 and init =
154 (declare_register_fcn name) ^
155 "{" ^
156 " X(kdft_register)(p, " ^ ename ^ ", &desc);\n" ^
157 "}\n"
158
159 in ((unparse tree) ^ "\n" ^
160 (if !Magic.standalone then "" else desc ^ init))
161
162 let main () =
163 begin
164 parse speclist usage;
165 print_string (generate (check_size ()));
166 end
167
168 let _ = main()