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 3349 - (view) (download)

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

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