Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/tree-ir/vector-layout.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/tree-ir/vector-layout.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3901 - (view) (download)

1 : jhr 3901 (* vector-layout.sml
2 : jhr 3828 *
3 :     * Functions for splitting LowIR vectors into TreeIR composite vectors.
4 :     *
5 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
6 :     *
7 :     * COPYRIGHT (c) 2016 The University of Chicago
8 :     * All rights reserved.
9 :     *)
10 :    
11 : jhr 3832 (* hardware support:
12 :     * SSE 128 bits
13 :     * AVX 256 bits (?)
14 :     * AVX2 256 bits
15 :     * AVX512 512 bits
16 :     *)
17 : jhr 3828
18 : jhr 3901 structure VectorLayout : sig
19 : jhr 3832
20 : jhr 3828 (* given a list of native vector sizes in ascending order, return a function for
21 :     * mapping vector widths to TreeTypes.VecTy values.
22 :     *)
23 : jhr 3832 val layout : int list -> int -> TreeTypes.vec_layout
24 :    
25 :     (* layout for a scalar target *)
26 :     val scalar : int -> TreeTypes.vec_layout
27 :    
28 :     (* `gccVectorSizes realIsDouble`
29 :     * returns a list of vector sizes that are valid for GCC vector extensions assuming
30 :     * a maximum width of 512 bits (AVX512). The argument should be true if a Diderot
31 :     * real value is double precision.
32 :     *)
33 :     val gccVectorSizes : bool -> int list
34 :    
35 :     (* given a list of native vector sizes in ascending order, return a function for
36 :     * testing the validity of a layout.
37 :     *)
38 :     val valid : int list -> TreeTypes.vec_layout -> bool
39 :    
40 :     end = struct
41 :    
42 : jhr 3828 fun layout (sizes : int list) = let
43 :     (* find smallest supported vector width that is >= n; return the largest
44 :     * size if n is bigger than the largest supported vector.
45 :     *)
46 :     fun find (n, []) = raise Fail "impossible"
47 :     | find (n, [sz]) = sz
48 : jhr 3854 | find (n, sz::szs) = if (n <= sz) then sz else find(n, szs)
49 : jhr 3828 (* split n into pieces *)
50 :     fun split (n, pieces) = let
51 :     val sz = find (n, sizes)
52 :     val pieces = sz :: pieces
53 :     val m = n - sz
54 :     in
55 :     if (m = 0)
56 :     then (false, rev pieces)
57 :     else if (m < 0)
58 :     then (true, rev pieces)
59 :     else split (m, pieces)
60 :     end
61 :     in
62 :     fn n => let
63 :     val (padded, pieces) = split (n, [])
64 :     in
65 : jhr 3832 {wid=n, padded=padded, pieces=pieces}
66 : jhr 3828 end
67 :     end
68 :    
69 : jhr 3832 fun scalar w = {wid=w, padded=false, pieces=List.tabulate(w, fn _ => 1)}
70 : jhr 3828
71 : jhr 3832 local
72 :     val log2MaxWidth = 6 (* maxWidth == 512/32 *)
73 :     fun twoToThe n = Word.toIntX(Word.<<(0w1, Word.fromInt n))
74 :     in
75 :     fun gccVectorSizes false = List.tabulate (log2MaxWidth, twoToThe)
76 :     | gccVectorSizes true = List.tabulate (log2MaxWidth-1, twoToThe)
77 :     end (* local *)
78 :    
79 :     fun valid (sizes : int list) = let
80 : jhr 3854 fun validSize sz = List.exists (fn sz' => (sz = sz')) sizes
81 : jhr 3832 fun check {wid, padded, pieces} = let
82 :     fun chkPieces ([], totWid) =
83 :     (wid = totWid) orelse (padded andalso (wid < totWid))
84 :     | chkPieces (p::ps, totWid) =
85 :     validSize p andalso chkPieces (ps, p+totWid)
86 : jhr 3834 in
87 :     (wid > 0) andalso chkPieces (pieces, 0)
88 :     end
89 : jhr 3832 in
90 : jhr 3834 check
91 : jhr 3832 end
92 :    
93 : jhr 3828 end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0