text stringlengths 12 786k |
|---|
let fix_int_precision prec str = let prec = abs prec in let len = String . length str in match str . [ 0 ] with | ( ' ' + | ' ' - | ' ' ) as c when prec + 1 > len -> let res = Bytes . make ( prec + 1 ) ' 0 ' in Bytes . set res 0 c ; String . blit str 1 res ( ... |
let string_to_caml_string str = let str = String . escaped str in let l = String . length str in let res = Bytes . make ( l + 2 ) ' " ' \ in String . unsafe_blit str 0 res 1 l ; Bytes . unsafe_to_string res |
let format_of_iconv = function | Int_d | Int_Cd -> " % d " | Int_pd -> " %+ d " | Int_sd -> " % d " | Int_i | Int_Ci -> " % i " | Int_pi -> " %+ i " | Int_si -> " % i " | Int_x -> " % x " | Int_Cx -> " %# x " | Int_X -> " % X " | Int_CX -> " %# X " ... |
let format_of_iconvL = function | Int_d | Int_Cd -> " % Ld " | Int_pd -> " %+ Ld " | Int_sd -> " % Ld " | Int_i | Int_Ci -> " % Li " | Int_pi -> " %+ Li " | Int_si -> " % Li " | Int_x -> " % Lx " | Int_Cx -> " %# Lx " | Int_X -> " % LX " | Int_CX -> " ... |
let format_of_iconvl = function | Int_d | Int_Cd -> " % ld " | Int_pd -> " %+ ld " | Int_sd -> " % ld " | Int_i | Int_Ci -> " % li " | Int_pi -> " %+ li " | Int_si -> " % li " | Int_x -> " % lx " | Int_Cx -> " %# lx " | Int_X -> " % lX " | Int_CX -> " ... |
let format_of_iconvn = function | Int_d | Int_Cd -> " % nd " | Int_pd -> " %+ nd " | Int_sd -> " % nd " | Int_i | Int_Ci -> " % ni " | Int_pi -> " %+ ni " | Int_si -> " % ni " | Int_x -> " % nx " | Int_Cx -> " %# nx " | Int_X -> " % nX " | Int_CX -> " ... |
let format_of_fconv fconv prec = let prec = abs prec in let symb = char_of_fconv ~ cF ' : g ' fconv in let buf = buffer_create 16 in buffer_add_char buf ' ' ; % bprint_fconv_flag buf fconv ; buffer_add_char buf ' . ' ; buffer_add_string buf ( Int . to_string prec ) ; buffer_add_char ... |
let transform_int_alt iconv s = match iconv with | Int_Cd | Int_Ci | Int_Cu -> let digits = let n = ref 0 in for i = 0 to String . length s - 1 do match String . unsafe_get s i with ' 0 ' . . ' 9 ' -> incr n | _ -> ( ) done ; ! n in let buf = Bytes . create ( String . len... |
let convert_int iconv n = transform_int_alt iconv ( format_int ( format_of_iconv iconv ) n ) |
let convert_int32 iconv n = transform_int_alt iconv ( format_int32 ( format_of_iconvl iconv ) n ) |
let convert_nativeint iconv n = transform_int_alt iconv ( format_nativeint ( format_of_iconvn iconv ) n ) |
let convert_int64 iconv n = transform_int_alt iconv ( format_int64 ( format_of_iconvL iconv ) n ) |
let convert_float fconv prec x = match snd fconv with | Float_h | Float_H -> ( let sign = match fst fconv with | Float_flag_p -> ' ' + | Float_flag_s -> ' ' | _ -> ' ' - in let str = hexstring_of_float x prec sign in match snd fconv with Float_H -> String . uppercase_ascii str | _ -> ... |
let format_caml_char c = let str = Char . escaped c in let l = String . length str in let res = Bytes . make ( l + 2 ) ' ' ' \ in String . unsafe_blit str 0 res 1 l ; Bytes . unsafe_to_string res |
let string_of_fmtty fmtty = let buf = buffer_create 16 in bprint_fmtty buf fmtty ; buffer_contents buf |
let rec make_printf : type a b c d e f . ( ( b , c ) acc -> f ) -> ( b , c ) acc -> ( a , b , c , d , e , f ) fmt -> a = fun k acc fmt -> match fmt with | Char rest -> fun c -> let new_acc = Acc_data_char ( acc , c ) in make_printf k new_acc rest | Caml_char rest -> fu... |
let const x _ = x |
let rec make_iprintf : type a b c d e f state . ( state -> f ) -> state -> ( a , b , c , d , e , f ) fmt -> a = fun k o fmt -> match fmt with | Char rest -> const ( make_iprintf k o rest ) | Caml_char rest -> const ( make_iprintf k o rest ) | String ( No_padding , rest ) -... |
let rec output_acc o acc = match acc with | Acc_formatting_lit ( p , fmting_lit ) -> let s = string_of_formatting_lit fmting_lit in output_acc o p ; output_string o s | Acc_formatting_gen ( p , Acc_open_tag acc ' ) -> output_acc o p ; output_string o " { " ; @ output_acc o acc ' | Ac... |
let rec bufput_acc b acc = match acc with | Acc_formatting_lit ( p , fmting_lit ) -> let s = string_of_formatting_lit fmting_lit in bufput_acc b p ; Buffer . add_string b s | Acc_formatting_gen ( p , Acc_open_tag acc ' ) -> bufput_acc b p ; Buffer . add_string b " { " ; @ bufput_acc... |
let rec strput_acc b acc = match acc with | Acc_formatting_lit ( p , fmting_lit ) -> let s = string_of_formatting_lit fmting_lit in strput_acc b p ; Buffer . add_string b s | Acc_formatting_gen ( p , Acc_open_tag acc ' ) -> strput_acc b p ; Buffer . add_string b " { " ; @ strput_acc... |
let failwith_message ( Format ( fmt , _ ) ) = let buf = Buffer . create 256 in let k acc = strput_acc buf acc ; failwith ( Buffer . contents buf ) in make_printf k End_of_acc fmt |
let open_box_of_string str = if str = " " then 0 , Pp_box else let len = String . length str in let invalid_box ( ) = failwith_message " invalid box description % S " str in let rec parse_spaces i = if i = len then i else match str . [ i ] with ' ' | ' \ t ' -> parse_spaces ( ... |
let make_padding_fmt_ebb : type x y . ( x , y ) padding -> ( _ , _ , _ , _ , _ , _ ) fmt -> ( _ , _ , _ , _ , _ ) padding_fmt_ebb = fun pad fmt -> match pad with | No_padding -> Padding_fmt_EBB ( No_padding , fmt ) | Lit_padding ( s , w ) -> Padding_fmt_... |
let make_precision_fmt_ebb : type x y . ( x , y ) precision -> ( _ , _ , _ , _ , _ , _ ) fmt -> ( _ , _ , _ , _ , _ ) precision_fmt_ebb = fun prec fmt -> match prec with | No_precision -> Precision_fmt_EBB ( No_precision , fmt ) | Lit_precision p -> Precision_... |
let make_padprec_fmt_ebb : type x y z t . ( x , y ) padding -> ( z , t ) precision -> ( _ , _ , _ , _ , _ , _ ) fmt -> ( _ , _ , _ , _ , _ ) padprec_fmt_ebb = fun pad prec fmt -> let ( Precision_fmt_EBB ( prec , fmt ' ) ) = make_precision_fmt_ebb pre... |
let fmt_ebb_of_string ? legacy_behavior str = let legacy_behavior = match legacy_behavior with Some flag -> flag | None -> true in let invalid_format_message str_ind msg = failwith_message " invalid format % S : at character number % d , % s " str str_ind msg in let unexpected_end_of_format end_ind = ... |
let format_of_string_fmtty str fmtty = let ( Fmt_EBB fmt ) = fmt_ebb_of_string str in try Format ( type_format fmt fmtty , str ) with Type_mismatch -> failwith_message " bad input : format type mismatch between % S and % S " str ( string_of_fmtty fmtty ) |
let format_of_string_format str ( Format ( fmt ' , str ' ) ) = let ( Fmt_EBB fmt ) = fmt_ebb_of_string str in try Format ( type_format fmt ( fmtty_of_fmt fmt ' ) , str ) with Type_mismatch -> failwith_message " bad input : format type mismatch between % S and % S " str str ' |
module Signal_map = struct type t = Signal . t Map . M ( Signal . Uid ) . t [ @@ deriving sexp_of ] let create graph = let add_signal map signal = let uid = Signal . uid signal in Map . add_exn map ~ key : uid ~ data : signal in Signal_graph . depth_first_search graph ~ init ( : Map ... |
type t = { name : string ; signal_by_uid : Signal_map . t ; inputs : Signal . t list ; outputs : Signal . t list ; phantom_inputs : ( string * int ) list ; signal_graph : Signal_graph . t ; fan_out : Signal . Uid_set . t Map . M ( Signal . Uid ) . t Lazy . t ; fan_in... |
module Summary = struct let sexp_of_signal signal = Signal . sexp_of_signal_recursive ~ depth : 0 signal let sexp_of_t t = [ % message " " ~ name ( : t . name : string ) ~ input_ports ( : t . inputs : signal list ) ~ output_ports ( : t . outputs : signal list ) ] ; ; end |
module Port_checks = struct type t = | Relaxed | Port_sets | Port_sets_and_widths end |
module Config = struct type t = { detect_combinational_loops : bool ; normalize_uids : bool ; assertions : Assertion_manager . t option ; port_checks : Port_checks . t ; add_phantom_inputs : bool ; modify_outputs : Signal . t list -> Signal . t list } let default = { detect_combination... |
let check_ports_in_one_direction direction ports = let find_repeated_names ports = let rec find seen repeated = function | [ ] -> seen , repeated | name :: ports -> if Set . mem seen name then find seen ( Set . add repeated name ) ports else find ( Set . add seen name ) repeated ports in let... |
let check_port_names_are_well_formed inputs outputs = let inputs = check_ports_in_one_direction " Input " inputs in let outputs = check_ports_in_one_direction " Output " outputs in let input_and_output_names = Set . inter inputs outputs in if not ( Set . is_empty input_and_output_names ) then raise_... |
let create_exn ( ? config = Config . default ) ~ name outputs = let assertions = match config . assertions with | Some assertions -> Assertion_manager . finalize assertions | None -> Map . empty ( module String ) in let output_names = List . concat_map outputs ~ f ( : fun signal -> if S... |
let set_phantom_inputs circuit phantom_inputs = let module Port = struct module T = struct type t = string * int [ @@ deriving sexp_of ] let compare ( n0 , _ ) ( n1 , _ ) = String . compare n0 n1 end include T include Comparable . Make ( T ) let of_signal port = let name = match Signa... |
let with_name t ~ name = { t with name } |
let uid_equal a b = Int64 . equal ( Signal . uid a ) ( Signal . uid b ) |
let is_input t signal = List . mem t . inputs signal ~ equal : uid_equal |
let is_output t signal = List . mem t . outputs signal ~ equal : uid_equal |
let find_signal_exn t uid = Map . find_exn t . signal_by_uid uid |
let fan_out_map t = Lazy . force t . fan_out |
let fan_in_map t = Lazy . force t . fan_in |
let signal_map c = c . signal_by_uid |
let assertions t = t . assertions |
let structural_compare ? check_names c0 c1 = let num_ports_match which_ports = List . length ( which_ports c0 ) = List . length ( which_ports c1 ) in let ports_match which_ports = let names_or_empty = function | Signal . Empty -> [ ] | s -> Signal . names s in match List . fold2 ( whic... |
let instantiations t = let instantiations = ref [ ] in Signal_graph . iter ( signal_graph t ) ~ f ( : function | Signal . Inst inst -> instantiations := inst . instantiation :: ! instantiations | _ -> ( ) ) ; ! instantiations ; ; |
module With_interface ( I : Interface . S_Of_signal ) ( O : Interface . S_Of_signal ) = struct type create = I . Of_signal . t -> O . Of_signal . t let check_io_port_sets_match circuit = let actual_ports ports = List . map ports ~ f : Signal . names |> List . concat |> Set . of_li... |
let create_with_interface ( type i o ) ( module I : Interface . S_Of_signal with type Of_signal . t = i ) ( module O : Interface . S_Of_signal with type Of_signal . t = o ) = let module C = With_interface ( I ) ( O ) in C . create_exn ; ; |
module Entry = struct type t = { name : string ; mangled_name : string ; circuit : Circuit . t } [ @@ deriving fields ] end |
type t = { mangler : Mangler . t ; entry_by_mangled_name : ( string , Entry . t ) Hashtbl . t } |
let sexp_of_t t = let mapping = List . map ( Hashtbl . data t . entry_by_mangled_name ) ~ f ( : fun e -> e . name , e . mangled_name ) |> List . sort ~ compare [ :% compare : string * string ] in [ % sexp ( mapping : ( string * string ) list ) ] ; ; |
let create ( ) = let mangler = Mangler . create ~ case_sensitive : false in List . iter Reserved_words . ( verilog @ vhdl ) ~ f ( : fun r -> ignore ( Mangler . add_identifier mangler r : [ ` Ok | ` Duplicate ] ) ) ; { mangler ; entry_by_mangled_name = Hashtbl . create ... |
let add t circuit = let name = Circuit . name circuit in let mangled_name = Mangler . mangle t . mangler name in let entry = { Entry . name ; mangled_name ; circuit = Circuit . with_name circuit ~ name : mangled_name } in Hashtbl . add_exn t . entry_by_mangled_name ~ key : mangled_name ~... |
let add_if_unique t circuit = match List . find ( Hashtbl . data t . entry_by_mangled_name ) ~ f ( : fun entry -> String . equal entry . name ( Circuit . name circuit ) && Circuit . structural_compare entry . circuit circuit ) with | Some e -> e . mangled_name | None -> add t circ... |
let insert ( ? share = true ) database circuit = if share then add_if_unique database circuit else add database circuit ; ; |
let find t ~ mangled_name = Hashtbl . find t . entry_by_mangled_name mangled_name |> Option . map ~ f : Entry . circuit ; ; |
let get_circuits ( t : t ) = List . map ( Hashtbl . data t . entry_by_mangled_name ) ~ f ( : fun ( e : Entry . t ) -> e . circuit ) ; ; |
module Total_bits = struct type t = { count : int ; total_bits : int } [ @@ deriving sexp_of ] let none = { count = 0 ; total_bits = 0 } let add ( ? u = none ) s = Some { count = u . count + 1 ; total_bits = u . total_bits + Signal . width s } ; ; end |
module Total_and_max_bits = struct type t = { count : int ; total_bits : int ; max_instance_bits : int } [ @@ deriving sexp_of ] let none = { count = 0 ; total_bits = 0 ; max_instance_bits = 0 } let add ( ? u = none ) s = let w = Signal . width s in Some { count = u . cou... |
module Multiplexer = struct type t = { max_instance_bits : int ; total_bits : int ; count : int } [ @@ deriving sexp_of ] end |
module Multiplexers = struct module Mux_map = struct type t = Multiplexer . t Map . M ( Int ) . t let sexp_of_elt ( number_of_data_elements , ( m : Multiplexer . t ) ) = let max_instance_bits = m . max_instance_bits in let total_bits = m . total_bits in let count = m . count in [ ... |
module Memory = struct module T = struct type t = { data_width : int ; depth : int ; total_bits : int } [ @@ deriving sexp_of , compare ] end include T include Comparable . Make ( T ) end |
module Memories = struct module Mem_map = struct type t = int Map . M ( Memory ) . t let sexp_of_elt ( { Memory . data_width ; depth ; total_bits } , count ) = [ % message ( data_width : int ) ( depth : int ) ( total_bits : int ) ( count : int ) ] ; ; let sexp_of... |
module rec Instantiation : sig type t = | Instantiation of string | Submodule of T . t [ @@ deriving sexp_of ] type t = | Instantiation of string | Submodule of T . t [ @@ deriving sexp_of ] end type t = Instantiation . t list [ @@ deriving sexp_of ] val add : ? u : t -> Signal . t -... |
type t = T . t [ @@ deriving sexp_of ] |
let rec create ? database circuit = let expand_submodules t = match database with | None -> t | Some database -> { t with T . instantiations = Option . map t . T . instantiations ~ f ( : fun instantiations -> List . map instantiations ~ f ( : function | Instantiation . Instantiation name... |
type arity = Lambda . function_kind * int |
type apply_kind = Lambda . region_close * Lambda . alloc_mode |
type ustructured_constant = | Uconst_float of float | Uconst_int32 of int32 | Uconst_int64 of int64 | Uconst_nativeint of nativeint | Uconst_block of int * uconstant list | Uconst_float_array of float list | Uconst_string of string | Uconst_closure of ufunction list * string * uconstant list | Uconst_ref o... |
type function_description = { fun_label : function_label ; fun_arity : arity ; mutable fun_closed : bool ; mutable fun_inline : ( Backend_var . With_provenance . t list * ulambda ) option ; mutable fun_float_const_prop : bool ; fun_region : bool ; } |
type value_approximation = Value_closure of alloc_mode * function_description * value_approximation | Value_tuple of alloc_mode * value_approximation array | Value_unknown | Value_const of uconstant | Value_global_field of string * int |
type usymbol_provenance = { original_idents : Ident . t list ; module_path : Path . t ; } |
type uconstant_block_field = | Uconst_field_ref of string | Uconst_field_int of int |
type preallocated_block = { symbol : string ; exported : bool ; tag : int ; fields : uconstant_block_field option list ; provenance : usymbol_provenance option ; } |
type preallocated_constant = { symbol : string ; exported : bool ; definition : ustructured_constant ; provenance : usymbol_provenance option ; } |
type with_constants = ulambda * preallocated_block list * preallocated_constant list |
let compare_floats x1 x2 = Int64 . compare ( Int64 . bits_of_float x1 ) ( Int64 . bits_of_float x2 ) |
let rec compare_float_lists l1 l2 = match l1 , l2 with | [ ] , [ ] -> 0 | [ ] , _ :: _ -> - 1 | _ :: _ , [ ] -> 1 | h1 :: t1 , h2 :: t2 -> let c = compare_floats h1 h2 in if c <> 0 then c else compare_float_lists t1 t2 |
let compare_constants c1 c2 = match c1 , c2 with | Uconst_ref ( lbl1 , _c1 ) , Uconst_ref ( lbl2 , _c2 ) -> String . compare lbl1 lbl2 | Uconst_int n1 , Uconst_int n2 -> Stdlib . compare n1 n2 | Uconst_ref _ , _ -> - 1 | Uconst_int _ , Uconst_ref _ -> 1 |
let rec compare_constant_lists l1 l2 = match l1 , l2 with | [ ] , [ ] -> 0 | [ ] , _ :: _ -> - 1 | _ :: _ , [ ] -> 1 | h1 :: t1 , h2 :: t2 -> let c = compare_constants h1 h2 in if c <> 0 then c else compare_constant_lists t1 t2 |
let rank_structured_constant = function | Uconst_float _ -> 0 | Uconst_int32 _ -> 1 | Uconst_int64 _ -> 2 | Uconst_nativeint _ -> 3 | Uconst_block _ -> 4 | Uconst_float_array _ -> 5 | Uconst_string _ -> 6 | Uconst_closure _ -> 7 |
let compare_structured_constants c1 c2 = match c1 , c2 with | Uconst_float x1 , Uconst_float x2 -> compare_floats x1 x2 | Uconst_int32 x1 , Uconst_int32 x2 -> Int32 . compare x1 x2 | Uconst_int64 x1 , Uconst_int64 x2 -> Int64 . compare x1 x2 | Uconst_nativeint x1 , Uconst_nativeint x2 -> Nativein... |
type boxed = | Boxed | Unboxed |
type memory_access_size = | Sixteen | Thirty_two | Sixty_four |
type primitive = | Pread_symbol of string | Pmakeblock of int * mutable_flag * block_shape * alloc_mode | Pfield of int | Pfield_computed | Psetfield of int * immediate_or_pointer * initialization_or_assignment | Psetfield_computed of immediate_or_pointer * initialization_or_assignment | Pfloatfield of in... |
let equal ( x : primitive ) ( y : primitive ) = x = y |
let comp_ml = kern trainingSet data res setSize dataSize -> let open Std in let tid = thread_idx_x + block_dim_x * block_idx_x in if tid < setSize then ( let mutable diff = 0 in let mutable toAdd = 0 in let mutable i = 0 in while ( i < dataSize ) do toAdd := data . [ < i ] > - trainingSet .... |
type labelPixels = { label : int ; pixels : int array } |
let devices = Spoc . Devices . init ( ) |
let dev = ref devices . ( try int_of_string Sys . argv . ( 1 ) with | _ -> 0 ) |
let auto_transfers = ref true |
let compute_gpu = ref true |
let trainSet_size = ref 5000 |
let data_size = ref 784 |
let trainSet = Spoc . Vector . create Spoc . Vector . int32 ( ! trainSet_size * ! data_size ) |
let results = Spoc . Vector . create Spoc . Vector . int32 ! trainSet_size |
let vect_validation = Spoc . Vector . create Spoc . Vector . int32 ! data_size |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.