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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3349 - (download) (annotate)
Tue Oct 27 15:16:36 2015 UTC (3 years, 11 months ago) by jhr
File size: 2349 byte(s)
making copyrights consistent for all code in the repository
(* nrrd-types.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 *
 * NOTE: we may want to generate this file at configure time so that we don't
 * have to track the nrrd type codes by hand
 *)

structure NrrdTypes =
  struct

    local
      structure N = CNames
      structure Ty = TreeIL.Ty
    in

  (* integer codes for nrrd types (must track nrrdEnums.h) *)
    val nrrdTypeUnknown : IntInf.int = 0
    val nrrdTypeInt : IntInf.int = 5
    val nrrdTypeLLong : IntInf.int = 7
    val nrrdTypeFloat : IntInf.int = 9
    val nrrdTypeDouble : IntInf.int = 10

  (* translate a TreeIL type to its nrrd type code *)
    fun toNrrdType ty = (case ty
           of Ty.BoolTy => nrrdTypeUnknown
            | Ty.StringTy => nrrdTypeUnknown
            | Ty.IntTy => (if !N.doublePrecision then nrrdTypeLLong else nrrdTypeInt)
            | Ty.TensorTy[] => (if !N.doublePrecision then nrrdTypeDouble else nrrdTypeFloat)
            | Ty.TensorTy[n] => (if !N.doublePrecision then nrrdTypeDouble else nrrdTypeFloat)
            | Ty.TensorTy[n, m] => (if !N.doublePrecision then nrrdTypeDouble else nrrdTypeFloat)
            | Ty.SeqTy(Ty.IntTy, _) => (if !N.doublePrecision then nrrdTypeLLong else nrrdTypeInt)
            | Ty.AddrTy(ImageInfo.ImgInfo{...}) => nrrdTypeUnknown
            | Ty.ImageTy(ImageInfo.ImgInfo{...}) => nrrdTypeUnknown
            | _ => raise Fail(concat["trNrrdType(", Ty.toString ty, ")"])
          (* end case *))

  (* translate a TreeIL type and shape to the correct memory size in bytes *)
    fun toNrrdSize ty = let
          val num = (case ty
                of Ty.BoolTy => 0
                 | Ty.StringTy => 0
                 | Ty.IntTy => 1
                 | Ty.TensorTy[] => 1
                 | Ty.TensorTy[n] => IntInf.fromInt n
                 | Ty.TensorTy[n, m] => IntInf.fromInt (n * m)
                 | Ty.SeqTy(_, n) => IntInf.fromInt n
                 | Ty.AddrTy(ImageInfo.ImgInfo{...}) => 0
                 | Ty.ImageTy(ImageInfo.ImgInfo{...}) => 0
                 | _ => raise Fail(concat["trNrrdType(", Ty.toString ty, ")"])
               (* end case *))
          in 
            num * (if !N.doublePrecision then 8 else 4)
          end

    end (* local *)
  end

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