text
stringlengths
12
786k
let rec eqtype rename type_pairs subst env t1 t2 = if t1 == t2 then ( ) else let t1 = repr t1 in let t2 = repr t2 in if t1 == t2 then ( ) else try match ( t1 . desc , t2 . desc ) with ( Tvar , Tvar ) when rename -> begin try normalize_subst subst ; if List . assq t1 ! subst != t2 the...
let equal env rename tyl1 tyl2 = try univar_pairs := [ ] ; eqtype_list rename ( TypePairs . create 11 ) ( ref [ ] ) env tyl1 tyl2 ; true with Unify _ -> false
let eqtype rename type_pairs subst env t1 t2 = univar_pairs := [ ] ; eqtype rename type_pairs subst env t1 t2
type class_match_failure = CM_Virtual_class | CM_Parameter_arity_mismatch of int * int | CM_Type_parameter_mismatch of ( type_expr * type_expr ) list | CM_Class_type_mismatch of class_type * class_type | CM_Parameter_mismatch of ( type_expr * type_expr ) list | CM_Val_type_mismatch of string * ( ty...
let rec moregen_clty trace type_pairs env cty1 cty2 = try match cty1 , cty2 with Tcty_constr ( _ , _ , cty1 ) , _ -> moregen_clty true type_pairs env cty1 cty2 | _ , Tcty_constr ( _ , _ , cty2 ) -> moregen_clty true type_pairs env cty1 cty2 | Tcty_fun ( l1 , ty1 , cty1 ' ) , ...
let match_class_types ( ? trace = true ) env pat_sch subj_sch = let type_pairs = TypePairs . create 53 in let old_level = ! current_level in current_level := generic_level - 1 ; let ( _ , subj_inst ) = instance_class [ ] subj_sch in let subj = duplicate_class_type subj_inst in current_lev...
let rec equal_clty trace type_pairs subst env cty1 cty2 = try match cty1 , cty2 with Tcty_constr ( _ , _ , cty1 ) , Tcty_constr ( _ , _ , cty2 ) -> equal_clty true type_pairs subst env cty1 cty2 | Tcty_constr ( _ , _ , cty1 ) , _ -> equal_clty true type_pairs subst env cty1 cty2...
let match_class_declarations env patt_params patt_type subj_params subj_type = let type_pairs = TypePairs . create 53 in let subst = ref [ ] in let sign1 = signature_of_class_type patt_type in let sign2 = signature_of_class_type subj_type in let t1 = repr sign1 . cty_self in let t2 = repr sign2 . cty_...
let warn = ref false
let pred_expand n = if n mod 2 = 0 && n > 0 then pred n else n
let pred_enlarge n = if n mod 2 = 1 then pred n else n
type change = Unchanged | Equiv | Changed
let collect l = List . fold_left ( fun c1 ( _ , c2 ) -> max c1 c2 ) Unchanged l
let rec filter_visited = function [ ] -> [ ] | { desc = Tobject _ | Tvariant _ } :: _ as l -> l | _ :: l -> filter_visited l
let memq_warn t visited = if List . memq t visited then ( warn := true ; true ) else false
let rec lid_of_path sharp = function Path . Pident id -> Longident . Lident ( sharp ^ Ident . name id ) | Path . Pdot ( p1 , s , _ ) -> Longident . Ldot ( lid_of_path " " p1 , sharp ^ s ) | Path . Papply ( p1 , p2 ) -> Longident . Lapply ( lid_of_path sharp p1 , li...
let find_cltype_for_path env p = let path , cl_abbr = Env . lookup_type ( lid_of_path " " # p ) env in match cl_abbr . type_manifest with Some ty -> begin match ( repr ty ) . desc with Tobject ( _ , { contents = Some ( p ' , _ ) } ) when Path . same p p ' -> cl_abbr , ...
let has_constr_row ' env t = has_constr_row ( expand_abbrev env t )
let rec build_subtype env visited loops posi level t = let t = repr t in match t . desc with Tvar -> if posi then try let t ' = List . assq t loops in warn := true ; ( t ' , Equiv ) with Not_found -> ( t , Unchanged ) else ( t , Unchanged ) | Tarrow ( l , t1 , t2 , _ ) -> ...
let enlarge_type env ty = warn := false ; let ( ty ' , _ ) = build_subtype env [ ] [ ] true 4 ty in ( ty ' , ! warn )
let subtypes = TypePairs . create 17
let subtype_error env trace = raise ( Subtype ( expand_trace env ( List . rev trace ) , [ ] ) )
let private_abbrev env path = try let decl = Env . find_type path env in decl . type_private = Private && decl . type_manifest <> None with Not_found -> false
let rec subtype_rec env trace t1 t2 cstrs = let t1 = repr t1 in let t2 = repr t2 in if t1 == t2 then cstrs else begin try TypePairs . find subtypes ( t1 , t2 ) ; cstrs with Not_found -> TypePairs . add subtypes ( t1 , t2 ) ( ) ; match ( t1 . desc , t2 . desc ) with ( Tvar , _ ...
let subtype env ty1 ty2 = TypePairs . clear subtypes ; univar_pairs := [ ] ; let cstrs = subtype_rec env [ ( ty1 , ty2 ) ] ty1 ty2 [ ] in TypePairs . clear subtypes ; function ( ) -> List . iter ( function ( trace0 , t1 , t2 , pairs ) -> try unify_pairs env t1 t2 pairs...
let rec unalias_object ty = let ty = repr ty in match ty . desc with Tfield ( s , k , t1 , t2 ) -> newty2 ty . level ( Tfield ( s , k , t1 , unalias_object t2 ) ) | Tvar | Tnil -> newty2 ty . level ty . desc | Tunivar -> ty | Tconstr _ -> newty2 ty . level Tvar | _ -> ass...
let unalias ty = let ty = repr ty in match ty . desc with Tvar | Tunivar -> ty | Tvariant row -> let row = row_repr row in let more = row . row_more in newty2 ty . level ( Tvariant { row with row_more = newty2 more . level more . desc } ) | Tobject ( ty , nm ) -> newty2 ty . level (...
let rec arity ty = match ( repr ty ) . desc with Tarrow ( _ , t1 , t2 , _ ) -> 1 + arity t2 | _ -> 0
let cyclic_abbrev env id ty = let rec check_cycle seen ty = let ty = repr ty in match ty . desc with Tconstr ( p , tl , abbrev ) -> p = Path . Pident id || List . memq ty seen || begin try check_cycle ( ty :: seen ) ( expand_abbrev_opt env ty ) with Cannot_expand -> false | Unify _ -> ...
let rec normalize_type_rec env visited ty = let ty = repr ty in if not ( TypeSet . mem ty ! visited ) then begin visited := TypeSet . add ty ! visited ; begin match ty . desc with | Tvariant row -> let row = row_repr row in let fields = List . map ( fun ( l , f0 ) -> let f = row_field_r...
let normalize_type env ty = normalize_type_rec env ( ref TypeSet . empty ) ty
let nondep_hash = TypeHash . create 47
let nondep_variants = TypeHash . create 17
let clear_hash ( ) = TypeHash . clear nondep_hash ; TypeHash . clear nondep_variants
let rec nondep_type_rec env id ty = match ty . desc with Tvar | Tunivar -> ty | Tlink ty -> nondep_type_rec env id ty | _ -> try TypeHash . find nondep_hash ty with Not_found -> let ty ' = newgenvar ( ) in TypeHash . add nondep_hash ty ty ' ; ty ' . desc <- begin match ty . desc with |...
let nondep_type env id ty = try let ty ' = nondep_type_rec env id ty in clear_hash ( ) ; ty ' with Not_found -> clear_hash ( ) ; raise Not_found
let unroll_abbrev id tl ty = let ty = repr ty and path = Path . Pident id in if ( ty . desc = Tvar ) || ( List . exists ( deep_occur ty ) tl ) || is_object_type path then ty else let ty ' = newty2 ty . level ty . desc in link_type ty ( newty2 ty . level ( Tconstr ( path , tl , ...
let nondep_type_decl env mid id is_covariant decl = try let params = List . map ( nondep_type_rec env mid ) decl . type_params in let tk = try match decl . type_kind with Type_abstract -> Type_abstract | Type_variant cstrs -> Type_variant ( List . map ( fun ( c , tl ) -> ( c , List . ...
let nondep_class_signature env id sign = { cty_self = nondep_type_rec env id sign . cty_self ; cty_vars = Vars . map ( function ( m , v , t ) -> ( m , v , nondep_type_rec env id t ) ) sign . cty_vars ; cty_concr = sign . cty_concr ; cty_inher = List . map ( fun ( p , tl...
let rec nondep_class_type env id = function Tcty_constr ( p , _ , cty ) when Path . isfree id p -> nondep_class_type env id cty | Tcty_constr ( p , tyl , cty ) -> Tcty_constr ( p , List . map ( nondep_type_rec env id ) tyl , nondep_class_type env id cty ) | Tcty_signature sign -> ...
let nondep_class_declaration env id decl = assert ( not ( Path . isfree id decl . cty_path ) ) ; let decl = { cty_params = List . map ( nondep_type_rec env id ) decl . cty_params ; cty_variance = decl . cty_variance ; cty_type = nondep_class_type env id decl . cty_type ; cty_path ...
let nondep_cltype_declaration env id decl = assert ( not ( Path . isfree id decl . clty_path ) ) ; let decl = { clty_params = List . map ( nondep_type_rec env id ) decl . clty_params ; clty_variance = decl . clty_variance ; clty_type = nondep_class_type env id decl . clty_type ; c...
let rec collapse_conj env visited ty = let ty = repr ty in if List . memq ty visited then ( ) else let visited = ty :: visited in match ty . desc with Tvariant row -> let row = row_repr row in List . iter ( fun ( l , fi ) -> match row_field_repr fi with Reither ( c , t1 ( :: _ :: _ as...
let collapse_conj_params env params = List . iter ( collapse_conj env [ ] ) params
let _ = ( Callback . register_exception " no_cuda_device " No_Cuda_Device ; Callback . register_exception " cuda_error_deinitialized " ERROR_DEINITIALIZED ; Callback . register_exception " cuda_error_not_initialized " ERROR_NOT_INITIALIZED ; Callback . register_exception " cuda_error_inv...
type point = { mutable x : float ; mutable y : float ; }
let customPoint = { size = getsizeofpoint ( ) ; get = extget ; set = extset ; }
let customPoint2 = { size = getsizeofpoint2 ( ) ; get = extget2 ; set = extset2 ; }
let cpuPI field size = let resVec = Array . map ( fun pt -> ( ( pt . x . * pt . x ) . + ( pt . y . * pt . y ) ) <= ( ray . * ray ) ) field in let res = Array . fold_left ( fun i res -> if res then i + 1 else i ) 0 resVec in res
let gpuPi_d dev ( block , grid ) ( gpuField , vbool , nbPoint , ray ) = if Spoc . Devices . allowDouble dev then Spoc . Kernel . run dev ( block , grid ) gpuPi_double ( gpuField , vbool , nbPoint , ( ray . * ray ) ) else Spoc . Kernel . run dev ( block , grid ) ...
let gpuPi_complex vbool dev size = let gpuField = Vector . create complex32 size in for i = 0 to size - 1 do Mem . set gpuField i { re = Random . float ray ; im = Random . float ray ; } ; done ; let threadsPerBlock = match dev . Devices . specific_info with | Devices . OpenCLInfo clI...
let gpuPI gpuField vbool dev size = let threadsPerBlock = match dev . Devices . specific_info with | Devices . OpenCLInfo clI -> ( match clI . Devices . device_type with | Devices . CL_DEVICE_TYPE_CPU -> 1 | _ -> 256 ) | _ -> 256 in let blocksPerGrid = ( ( ( size / 32 ) + thre...
let multiGpuPI gpuField1 gpuField2 vbool1 vbool2 dev1 dev2 size = let threadsPerBlock = 512 in let blocksPerGrid = ( ( ( ( size / 32 ) / 2 ) + threadsPerBlock ) - 1 ) / threadsPerBlock in let block = { Spoc . Kernel . blockX = threadsPerBlock ; Spoc . Kernel . blockY = 1 ; ...
let _ = ( Random . self_init ( ) ; let devices = Spoc . Devices . init ( ) in let dev = ref devices . ( 0 ) in let size = ref nbPoint in let arg1 = ( " - device " , Arg . Int ( fun i -> dev := devices . ( i ) ) , " number of the device [ 0 ] " ) and arg...
type ( ' i , ' o ) t = ( ' i , ' o ) Cyclesim0 . t [ @@ deriving sexp_of ]
let digest t = Cyclesim0 . digest t
module Violated_or_not = struct type t = | Violated of int list | Not_violated [ @@ deriving sexp_of ] end
let results_of_assertions ( t : _ t ) = Map . mapi t . assertions ~ f ( : fun ~ key ~ data : _ -> match Hashtbl . find t . violated_assertions key with | Some cycles -> Violated_or_not . Violated ( List . rev cycles ) | None -> Violated_or_not . Not_violated ) ; ;
let circuit ( sim : _ t ) = sim . circuit
let cycle_check ( sim : _ t ) = sim . cycle_check ( )
let cycle_before_clock_edge ( sim : _ t ) = sim . cycle_before_clock_edge ( )
let cycle_at_clock_edge ( sim : _ t ) = sim . cycle_at_clock_edge ( )
let cycle_after_clock_edge ( sim : _ t ) = sim . cycle_after_clock_edge ( )
let reset ( sim : _ t ) = sim . reset ( )
let cycle sim = cycle_check sim ; cycle_before_clock_edge sim ; cycle_at_clock_edge sim ; cycle_after_clock_edge sim ; ;
let in_port ( sim : _ Cyclesim0 . t ) name = try List . Assoc . find_exn sim . in_ports name ~ equal : String . equal with | _ -> raise_s [ % message " Couldn ' t find input port " name ] ; ;
let out_port_after_clock_edge ( sim : _ Cyclesim0 . t ) name = try List . Assoc . find_exn sim . out_ports_after_clock_edge name ~ equal : String . equal with | _ -> raise_s [ % message " Couldn ' t find output port " name ] ; ;
let out_port_before_clock_edge ( sim : _ Cyclesim0 . t ) name = try List . Assoc . find_exn sim . out_ports_before_clock_edge name ~ equal : String . equal with | _ -> raise_s [ % message " Couldn ' t find output port " name ] ; ;
let out_port ( ? clock_edge = Side . After ) t name = match clock_edge with | Before -> out_port_before_clock_edge t name | After -> out_port_after_clock_edge t name ; ;
let out_ports ( ? clock_edge = Side . After ) ( t : _ t ) = match clock_edge with | Before -> t . out_ports_before_clock_edge | After -> t . out_ports_after_clock_edge ; ;
let outputs ( ? clock_edge = Side . After ) ( t : _ t ) = match clock_edge with | Before -> t . outputs_before_clock_edge | After -> t . outputs_after_clock_edge ; ;
module With_interface ( I : Interface . S ) ( O : Interface . S ) = struct type nonrec t = ( Bits . t ref I . t , Bits . t ref O . t ) t [ @@ deriving sexp_of ] module C = Circuit . With_interface ( I ) ( O ) let coerce sim = let find_port ports ( name , width ) = m...
module Port_list = struct type t = ( string * Bits . t ref ) list [ @@ deriving sexp_of ] end
type task = unit -> unit
module Digest = struct type t = Md5_lib . t let sexp_of_t t = [ % sexp_of : string ] ( Md5_lib . to_hex t : string ) let compare a b = String . compare ( Md5_lib . to_binary a ) ( Md5_lib . to_binary b ) let equal a b = String . equal ( Md5_lib . to_binary a ) ( Md5_lib . t...
type ( ' i , ' o ) t = { in_ports : Port_list . t ; out_ports_before_clock_edge : Port_list . t ; out_ports_after_clock_edge : Port_list . t ; internal_ports : Port_list . t ; inputs : ' i ; outputs_after_clock_edge : ' o ; outputs_before_clock_edge : ' o ; reset : task ...
let sexp_of_t sexp_of_i sexp_of_o t = [ % message " " ~ inputs ( : t . inputs : i ) ~ outputs_before_clock_edge ( : t . outputs_before_clock_edge : o ) ~ outputs_after_clock_edge ( : t . outputs_after_clock_edge : o ) ] ; ;
type t_port_list = ( Port_list . t , Port_list . t ) t
module Config = struct type t = { is_internal_port : ( Signal . t -> bool ) option ; combinational_ops_database : Combinational_ops_database . t ; compute_digest : bool ; deduplicate_signals : bool ; store_circuit : bool } let empty_ops_database = Combinational_ops_database . create ( )...
module type Private = Cyclesim0_intf . Private
module Private = struct type nonrec ( ' i , ' o ) t = ( ' i , ' o ) t type nonrec port_list = Port_list . t type nonrec t_port_list = t_port_list type nonrec task = task let create ~ in_ports ~ out_ports_before_clock_edge ~ out_ports_after_clock_edge ~ internal_ports ~ reset ~ cycle_che...
module type Private = sig type ( ' i , ' o ) t type port_list type t_port_list type task = unit -> unit val create : in_ports : port_list -> out_ports_before_clock_edge : port_list -> out_ports_after_clock_edge : port_list -> internal_ports : port_list -> reset : task -> cycle_check : task -> ...
module type Cyclesim0 = sig module Port_list : sig type t = ( string * Bits . t ref ) list [ @@ deriving sexp_of ] end module Digest : sig type t = Md5_lib . t [ @@ deriving sexp_of , compare , equal ] val none : t end type task = unit -> unit type ( ' i , ' o ) t = { in_port...
module Combine_error = struct type t = { cycle_no : int ; clock_edge : Side . t ; port_name : string ; value0 : Bits . t ; value1 : Bits . t } [ @@ deriving sexp_of ] end
let default_on_error error = raise_s [ % message " [ Cyclesim . combine ] output port values differ " ( error : Combine_error . t ) ] ; ;
let combine ( ? port_sets_may_differ = false ) ( ? on_error = default_on_error ) ( s0 : _ t ) ( s1 : _ t ) = let si = Set . to_list ( List . fold ( s0 . in_ports @ s1 . in_ports ) ~ init ( : Set . empty ( module String ) ) ~ f ( : fun s ( n , _ ) -> Set ....
module Mangle_names = struct module IntPair = struct module T = struct type t = Signal . Uid . t * int [ @@ deriving compare , sexp_of ] end include T include Comparator . Make ( T ) end let port_names_map ports = List . fold ports ~ init ( : Map . empty ( module IntPair ) ) ~ f ( ...
module Internal_ports = struct let create circuit ~ is_internal_port = let name = Staged . unstage ( Mangle_names . create [ ] " _ " circuit ) in let i = match is_internal_port with | None -> [ ] | Some f -> Signal_graph . filter ( Circuit . signal_graph circuit ) ~ f ( : fun s...
module Maps : sig type t val create : Schedule . t -> t val find_data_by_uid_exn : t -> Signal . Uid . t -> Bits . Mutable . t val find_reg_by_uid_exn : t -> Signal . Uid . t -> Bits . Mutable . t val find_data_exn : t -> Signal . t -> Bits . Mutable . t val find_data : t -> Signal...
module Io_ports = struct type ' a t = { in_ports : ' a ; out_ports : ' a ; internal_ports : ' a } let create circuit maps internal_ports : _ t = let in_ports = List . map ( Circuit . inputs circuit ) ~ f ( : fun signal -> List . hd_exn ( names signal ) , Maps . find_data_...
module Compile = struct let mutable_to_int x = Int64 . to_int_trunc ( Bits . Mutable . unsafe_get_int64 x 0 ) let zero n = Bits . Mutable . of_constant ( Constant . of_int ~ width : n 0 ) let dispach_on_width width ~ less_than_64 ~ exactly_64 ~ more_than_64 = Some ( if width <= 64 the...
module Last_layer = struct let create ~ schedule circuit tasks_comb = let nodes = Signal_graph . last_layer_of_nodes ~ is_input ( : Circuit . is_input circuit ) ( Circuit . signal_graph circuit ) |> List . filter ~ f ( : fun uid -> not ( Schedule . is_alias schedule uid ) ) |> Set ....
module Compute_digest = struct let create out_ports_before out_ports_after internal_ports = let digest = ref ( Md5_lib . string " digest of hardcaml simulation " ) in let digest_length = String . length ( Md5_lib . to_binary ! digest ) in let ports = [ out_ports_before ; out_ports_after ; ...
let create ( ? config = Cyclesim0 . Config . default ) circuit = let circuit = if config . deduplicate_signals then Dedup . deduplicate circuit else circuit in let assertions = Circuit . assertions circuit in let internal_ports = Internal_ports . create circuit ~ is_internal_port : config . is...
module Width = struct type t = | W32 | W64 [ @@ deriving sexp_of ] let num_bits = function | W32 -> 32 | W64 -> 64 ; ; end
let op2 op name ( width : Width . t ) = let create_fn i o = match i , o with | [ x ; y ] , [ z ] -> let x = Bits . Mutable . unsafe_get_int64 x 0 in let y = Bits . Mutable . unsafe_get_int64 y 0 in ( match width with | W32 -> let x = Int32 . of_int64_trunc x |> Int32 . flo...
let op1 op name ( width : Width . t ) = let create_fn i o = match i , o with | [ x ] , [ z ] -> let x = Bits . Mutable . unsafe_get_int64 x 0 in ( match width with | W32 -> let x = Int32 . of_int64_trunc x |> Int32 . float_of_bits in let z ' = op x |> Int32 . bits_of_float ...
module F ( P : sig val width : Width . t end ) = struct let database = Combinational_ops_database . create ( ) let n s = String . concat ~ sep " : _ " [ " float " ; Int . to_string ( Width . num_bits P . width ) ; s ] let get_output = function | [ a ] -> a | _ -...
module Float = F ( struct let width = Width . W32 end )
module Double = F ( struct let width = Width . W64 end )