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

SCM Repository

[diderot] Annotation of /branches/cuda/src/compiler/c-util/nrrd-types.sml
ViewVC logotype

Annotation of /branches/cuda/src/compiler/c-util/nrrd-types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1640 - (view) (download)
Original Path: trunk/src/compiler/c-util/nrrd-types.sml

1 : jhr 1640 (* nrrd-types.sml
2 :     *
3 :     * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * NOTE: we may want to generate this file at configure time so that we don't
7 :     * have to track the nrrd type codes by hand
8 :     *)
9 :    
10 :     structure NrrdTypes =
11 :     struct
12 :    
13 :     local
14 :     structure N = CNames
15 :     structure Ty = TreeIL.Ty
16 :     in
17 :    
18 :     (* integer codes for nrrd types (must track nrrdEnums.h) *)
19 :     val nrrdTypeUnknown : IntInf.int = 0
20 :     val nrrdTypeInt : IntInf.int = 5
21 :     val nrrdTypeLLong : IntInf.int = 7
22 :     val nrrdTypeFloat : IntInf.int = 9
23 :     val nrrdTypeDouble : IntInf.int = 10
24 :    
25 :     (* translate a TreeIL type to its nrrd type code *)
26 :     fun toNrrdType ty = (case ty
27 :     of Ty.BoolTy => nrrdTypeUnknown
28 :     | Ty.StringTy => nrrdTypeUnknown
29 :     | Ty.IntTy => (if !N.doublePrecision then nrrdTypeLLong else nrrdTypeInt)
30 :     | Ty.TensorTy[] => (if !N.doublePrecision then nrrdTypeDouble else nrrdTypeFloat)
31 :     | Ty.TensorTy[n] => (if !N.doublePrecision then nrrdTypeDouble else nrrdTypeFloat)
32 :     | Ty.TensorTy[n, m] => (if !N.doublePrecision then nrrdTypeDouble else nrrdTypeFloat)
33 :     | Ty.SeqTy(Ty.IntTy, _) => (if !N.doublePrecision then nrrdTypeLLong else nrrdTypeInt)
34 :     | Ty.AddrTy(ImageInfo.ImgInfo{...}) => nrrdTypeUnknown
35 :     | Ty.ImageTy(ImageInfo.ImgInfo{...}) => nrrdTypeUnknown
36 :     | _ => raise Fail(concat["trNrrdType(", Ty.toString ty, ")"])
37 :     (* end case *))
38 :    
39 :     (* translate a TreeIL type and shape to the correct memory size in bytes *)
40 :     fun toNrrdSize ty = let
41 :     val num = (case ty
42 :     of Ty.BoolTy => 0
43 :     | Ty.StringTy => 0
44 :     | Ty.IntTy => 1
45 :     | Ty.TensorTy[] => 1
46 :     | Ty.TensorTy[n] => IntInf.fromInt n
47 :     | Ty.TensorTy[n, m] => IntInf.fromInt (n * m)
48 :     | Ty.SeqTy(_, n) => IntInf.fromInt n
49 :     | Ty.AddrTy(ImageInfo.ImgInfo{...}) => 0
50 :     | Ty.ImageTy(ImageInfo.ImgInfo{...}) => 0
51 :     | _ => raise Fail(concat["trNrrdType(", Ty.toString ty, ")"])
52 :     (* end case *))
53 :     in
54 :     num * (if !N.doublePrecision then 8 else 4)
55 :     end
56 :    
57 :     end (* local *)
58 :     end

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