text
stringlengths
12
786k
let block = { Spoc . Kernel . blockX = 1024 ; Spoc . Kernel . blockY = 1 ; Spoc . Kernel . blockZ = 1 ; }
let grid = { Spoc . Kernel . gridX = 5 ; Spoc . Kernel . gridY = 1 ; Spoc . Kernel . gridZ = 1 ; }
let parse_args ( ) = let arg1 = ( " - device " , Arg . Int ( fun i -> dev := devices . ( i ) ) , " number of the device [ 0 ] " ) and arg2 = ( " - auto " , Arg . Bool ( fun b -> auto_transfers := b ) , " let Spoc handles transfers automatically [ false ]...
let load_data_to_GPU data = Printf . printf " Will use device : % s \ n " ( ! dev ) . Spoc . Devices . general_info . Spoc . Devices . name ; Printf . printf " Loading a vector with the training data \ n " ; %! let f = ( fun index elem -> let pix_list = elem . pixels in for...
let read_lines name : string list = Printf . printf " Reading data from file : % s \ n " %! name ; let ic = open_in name in let try_read ( ) = try Some ( input_line ic ) with End_of_file -> None in let rec loop acc = match try_read ( ) with | Some s -> loop ( s :: acc ) | None -> ...
let slurp_file file = List . tl ( read_lines file ) |> List . map ( fun line -> Str . split ( Str . regexp " , " ) line ) |> List . map ( fun numline -> List . map ( fun ( x : string ) -> int_of_string x ) numline ) |> List . map ( fun line -> { label = List . ...
let array_fold_left2 f acc a1 a2 = let open Array in let len = length a1 in let rec iter acc i = if i = len then acc else let v1 = unsafe_get a1 i in let v2 = unsafe_get a2 i in iter ( f acc v1 v2 ) ( i + 1 ) in iter acc 0
let distance p1 p2 = sqrt @@ float_of_int @@ array_fold_left2 ( fun acc a b -> let d = a - b in acc + d * d ) 0 p1 p2
let classify ( pixels : int array ) trainingset = fst ( Array . fold_left ( fun ( ( min_label , min_dist ) as min ) ( x : labelPixels ) -> let dist = distance pixels x . pixels in if dist < min_dist then ( x . label , dist ) else min ) ( max_int , max_float ) trainingset ...
let r = ref true
let classify_gpu ( pixels : int array ) trainingset = Array . iteri ( fun i x -> Spoc . Mem . set vect_validation i ( Int32 . of_int x ) ) pixels ; if ( not ! auto_transfers ) then Spoc . Mem . to_device vect_validation ! dev ; if ! r then ( r := not ! r ; Kirc . profile_ru...
let num_correct trainingset validationsample = load_data_to_GPU trainingset ; if ! compute_gpu then Array . fold_left ( fun sum p -> sum + if classify_gpu p . pixels trainingset = p . label then 1 else 0 ) 0 validationsample else Array . fold_left ( fun sum p -> sum + if classify p . pixels ...
let _ = parse_args ( ) ; let validationsample = slurp_file " . / validationsample . csv " in let trainingset = slurp_file " . / trainingsample . csv " in Printf . printf " \ nResults with training set of % i vectors of length % i \ n " %! ! trainSet_size ! data_size ; Printf ....
module Make ( Ast : Sig . Camlp4Ast ) = struct class clean_ast = object inherit Ast . map as super ; method with_constr wc = match super # with_constr wc with [ <: with_constr < $ <: with_constr <>> $ and $ wc $ >> | <: with_constr < $ wc $ and $ <: with_constr <>> $ >> -> wc | wc ...
let objfiles = ref ( [ ] : string list )
let compile_only = ref false
let annotations = ref false
let dump_parsetree = ref false
let keep_asm_file = ref false
let optimize_for_speed = ref true
let register_allocator = ref Config . default_register_allocator
let keep_startup_file = ref false
let native_code = ref false
let inline_threshold = ref 10
let dont_write_files = ref false
let std_include_flag prefix = if ! no_std_include then " " else ( prefix ^ ( Filename . quote Config . standard_library ) ) ; ;
let std_include_dir ( ) = if ! no_std_include then [ ] else [ Config . standard_library ] ; ;
let shared = ref false
let dlcode = ref true
module Constants = struct let runtime_api_version = " 2018 - 06 - 01 " let api_content_type = " application / json " let api_error_content_type = " application / vnd . aws . lambda . error + json " let runtime_error_header = " Lambda - Runtime - Function - Error - Type " module Re...
type client_application = { installation_id : string ; app_title : string option [ @ default None ] ; app_version_name : string ; app_version_code : string ; app_package_name : string }
type client_context = { client : client_application ; custom : Yojson . Safe . t ; env : Yojson . Safe . t }
type cognito_identity = { identity_id : string ; identity_pool_id : string }
type event_context = { invoked_function_arn : string ; aws_request_id : string ; xray_trace_id : string option [ @ default None ] ; deadline : int64 ; client_context : client_context option ; identity : cognito_identity option }
let make endpoint = let uri = Uri . of_string ( Format . asprintf " http ://% s " endpoint ) in Piaf . Client . create uri >|= function | Ok connection -> Ok connection | Error msg -> Error msg
let make_runtime_post_request client path output = let body = Yojson . Safe . to_string output in Piaf . Client . post client ~ headers [ : " Content - Type " , Constants . api_content_type ] ~ body ( : Piaf . Body . of_string body ) path
let event_response client request_id output = let open Piaf in let path = Format . asprintf " /% s / runtime / invocation /% s / response " Constants . runtime_api_version request_id in make_runtime_post_request client path output >>= function | Ok { Response . status ; _ } -> if not ( Stat...
let make_runtime_error_request connection path error = let open Piaf in let body = Errors . to_lambda_error error |> Yojson . Safe . to_string in Client . post connection ~ headers : [ " Content - Type " , Constants . api_error_content_type ; Constants . runtime_error_header , " RuntimeE...
let event_error client request_id err = let open Piaf in let path = Format . asprintf " /% s / runtime / invocation /% s / error " Constants . runtime_api_version request_id in make_runtime_error_request client path err >>= function | Ok { Response . status ; _ } -> if not ( Status . is_s...
let fail_init client err = let path = Format . asprintf " /% s / runtime / init / error " Constants . runtime_api_version in make_runtime_error_request client path err >>= function | Ok _ -> Lwt_result . return ( ) | Error _ -> failwith " Error while sending init failed message "
let get_event_context headers = let open Piaf in let report_error header = let err = Errors . make_api_error ~ recoverable : true ( Printf . sprintf " Missing % s header " header ) in Error err in let open Constants in match Headers . get headers RequestHeaders . request_id with | None -> report...
let next_event client = let open Piaf in let path = Format . asprintf " /% s / runtime / invocation / next " Constants . runtime_api_version in Logs_lwt . info ( fun m -> m " Polling for next event . Path : % s \ n " path ) >>= fun ( ) -> Client . get client path >>= function | O...
let with_channels f = let section = Lwt_log_core . Section . make " with_channels " in let make_channel name ( ic , oc ) = let read c = let len = Cstruct . len c in Lwt_log . debug_f ~ section " % s read : % d " name len >>= fun ( ) -> let b = Bytes . create len in Lwt_io . rea...
let test ~ server ~ client ( ) = Lwt_log . add_rule " " * Lwt_log . Debug ; with_channels ( fun client_channel server_channel -> let test_server = server server_channel in let cancel , _ = Lwt . task ( ) in let test_server = Lwt . catch ( fun ( ) -> Lwt . pick [ test_server...
let check msg = function | Result . Ok a -> Lwt . return a | Result . Error _ -> Lwt . fail_with msg
let test_connect_disconnect _switch = let test_block = Cstruct . of_string " asdf " in test ~ server ( : fun server_channel -> Nbd . Server . connect server_channel ( ) >>= fun ( export_name , svr ) -> Alcotest . ( check string ) " export name received by server " " export1 " ...
let test_list_exports _switch = test ~ server ( : fun server_channel -> Lwt . catch ( fun ( ) -> Nbd . Server . connect ~ offer [ " : export1 " ; " export2 " ] server_channel ( ) >>= fun _ -> Alcotest . fail " Server should not enter transmission mode " ) ( function ...
let test_read_write _switch = let test_block = Cstruct . of_string " asdf " in test ~ server ( : fun server_channel -> Nbd . Server . connect server_channel ( ) >>= fun ( _export_name , svr ) -> Nbd . Server . serve svr ~ read_only : false ( module Cstruct_block . Block ) test...
let tests = let t = Alcotest_lwt . test_case in ( " Nbd client - server connection tests " , [ t " test_connect_disconnect " ` Quick test_connect_disconnect ; t " test_list_exports " ` Quick test_list_exports ; t " test_read_write " ` Quick test_read_write ] )
let pi = acos ( - 1 . ) val canvas = Canvas . create ~ width : 100 ~ height : 100 parent val mutable height = 100 val mutable width = 100 val mutable rflag = - 1 method x x0 = truncate ( float width . * ( x0 . + 1 . ) . / 2 . ) method y y0 = truncate ( float height . ...
let top = openTk ( )
let clock = new clock ~ parent : top
let _ = mainLoop ( )
module Storer = Switch . Store ( struct type t = lambda type key = lambda let make_key = Lambda . make_key let compare_key = Stdlib . compare end )
let no_phantom_lets ( ) = Misc . fatal_error " Closure does not support phantom let generation "
let rec split_list n l = if n <= 0 then ( [ ] , l ) else begin match l with [ ] -> fatal_error " Closure . split_list " | a :: l -> let ( l1 , l2 ) = split_list ( n - 1 ) l in ( a :: l1 , l2 ) end
let rec build_closure_env env_param pos = function [ ] -> V . Map . empty | id :: rem -> V . Map . add id ( Uprim ( P . Pfield pos , [ Uvar env_param ] , Debuginfo . none ) ) ( build_closure_env env_param ( pos + 1 ) rem )
let getglobal dbg id = Uprim ( P . Pread_symbol ( Compilenv . symbol_for_global id ) , [ ] , dbg )
let region ulam = let is_trivial = match ulam with | Uvar _ | Uconst _ -> true | _ -> false in if is_trivial then ulam else Uregion ulam
let tail ulam = let is_trivial = match ulam with | Uvar _ | Uconst _ -> true | _ -> false in if is_trivial then ulam else Utail ulam
let occurs_var var u = let rec occurs = function Uvar v -> v = var | Uconst _ -> false | Udirect_apply ( _lbl , args , _ , _ , _ ) -> List . exists occurs args | Ugeneric_apply ( funct , args , _ , _ ) -> occurs funct || List . exists occurs args | Uclosure ( _fundecls , ...
let prim_size prim args = let open Clambda_primitives in match prim with | Pread_symbol _ -> 1 | Pmakeblock _ -> 5 + List . length args | Pfield _ -> 1 | Psetfield ( _f , isptr , init ) -> begin match init with | Root_initialization -> 1 | Assignment _ | Heap_initialization -> match is...
let lambda_smaller lam threshold = let size = ref 0 in let rec lambda_size lam = if ! size > threshold then raise Exit ; match lam with Uvar _ -> ( ) | Uconst _ -> incr size | Udirect_apply ( _ , args , None , _ , _ ) -> size := ! size + 4 ; lambda_list_size args | Udirect_apply...
let is_pure_prim p = let open Semantics_of_primitives in match Semantics_of_primitives . for_primitive p with | ( No_effects | Only_generative_effects ) , _ -> true | Arbitrary_effects , _ -> false
let rec is_pure = function Uvar _ -> true | Uconst _ -> true | Uprim ( p , args , _ ) -> is_pure_prim p && List . for_all is_pure args | Uoffset ( arg , _ ) -> is_pure arg | Ulet ( Immutable , _ , _var , def , body ) -> is_pure def && is_pure body | Uregion body -> is_pur...
let make_const c = ( Uconst c , Value_const c )
let make_const_ref c = make_const ( Uconst_ref ( Compilenv . new_structured_constant ~ shared : true c , Some c ) )
let make_const_int n = make_const ( Uconst_int n )
let make_const_bool b = make_const_int ( if b then 1 else 0 )
let make_integer_comparison cmp x y = let open Clambda_primitives in make_const_bool ( match cmp with Ceq -> x = y | Cne -> x <> y | Clt -> x < y | Cgt -> x > y | Cle -> x <= y | Cge -> x >= y )
let make_float_comparison cmp x y = make_const_bool ( match cmp with | CFeq -> x = y | CFneq -> not ( x = y ) | CFlt -> x < y | CFnlt -> not ( x < y ) | CFgt -> x > y | CFngt -> not ( x > y ) | CFle -> x <= y | CFnle -> not ( x <= y ) | CFge -> x >= y | CFnge -> not ( x...
let make_const_float n = make_const_ref ( Uconst_float n )
let make_const_natint n = make_const_ref ( Uconst_nativeint n )
let make_const_int32 n = make_const_ref ( Uconst_int32 n )
let make_const_int64 n = make_const_ref ( Uconst_int64 n )
let simplif_arith_prim_pure ~ backend fpc p ( args , approxs ) dbg = let module B = ( val backend : Backend_intf . S ) in let open Clambda_primitives in let default = ( Uprim ( p , args , dbg ) , Value_unknown ) in match approxs with | [ Value_const ( Uconst_int n1 ) ] -> begin ...
let field_approx n = function | Value_tuple ( _ , a ) when n < Array . length a -> a . ( n ) | Value_const ( Uconst_ref ( _ , Some ( Uconst_block ( _ , l ) ) ) ) when n < List . length l -> Value_const ( List . nth l n ) | _ -> Value_unknown
let simplif_prim_pure ~ backend fpc p ( args , approxs ) dbg = let open Clambda_primitives in match p , args , approxs with | Pmakeblock ( tag , Immutable , _kind , mode ) , _ , _ -> let field = function | Value_const c -> c | _ -> raise Exit in begin try let cst = Uconst_block ( ...
let simplif_prim ~ backend fpc p ( args , approxs as args_approxs ) dbg = if List . for_all is_pure args then simplif_prim_pure ~ backend fpc p args_approxs dbg else let approx = match p with | P . Pmakeblock ( _ , Immutable , _kind , mode ) -> Value_tuple ( mode , Array . of_list appr...
let approx_ulam = function Uconst c -> Value_const c | _ -> Value_unknown
let find_action idxs acts tag = if 0 <= tag && tag < Array . length idxs then begin let idx = idxs . ( tag ) in assert ( 0 <= idx && idx < Array . length acts ) ; Some acts . ( idx ) end else None
let subst_debuginfo loc dbg = if ! Clflags . debug then Debuginfo . inline loc dbg else dbg
let rec substitute loc ( ( backend , fpc ) as st ) sb rn ulam = match ulam with Uvar v -> begin try V . Map . find v sb with Not_found -> ulam end | Uconst _ -> ulam | Udirect_apply ( lbl , args , probe , kind , dbg ) -> let dbg = subst_debuginfo loc dbg in Udirect_apply ( lbl , L...
type env = { backend : ( module Backend_intf . S ) ; cenv : ulambda V . Map . t ; fenv : value_approximation V . Map . t ; mutable_vars : V . Set . t ; }
let rec is_substituable ~ mutable_vars = function | Uvar v -> not ( V . Set . mem v mutable_vars ) | Uconst _ -> true | Uoffset ( arg , _ ) -> is_substituable ~ mutable_vars arg | _ -> false
let is_erasable = function | Uclosure _ -> true | u -> is_pure u
let bind_params { backend ; mutable_vars ; _ } loc fdesc params args funct body = let fpc = fdesc . fun_float_const_prop in let rec aux subst pl al body = match ( pl , al ) with ( [ ] , [ ] ) -> substitute ( Debuginfo . from_location loc ) ( backend , fpc ) subst ( Some ...
let warning_if_forced_inlined ~ loc ~ attribute warning = if attribute = Always_inlined then Location . prerr_warning ( Debuginfo . Scoped_location . to_location loc ) ( Warnings . Inlining_impossible warning )
let fail_if_probe ~ probe msg = match probe with | None -> ( ) | Some { name } -> Misc . fatal_errorf " Closure probe % s handler : % s " name msg
let direct_apply env fundesc ufunct uargs pos mode ~ probe ~ loc ~ attribute = match fundesc . fun_inline , attribute with | _ , Never_inlined | None , _ -> let dbg = Debuginfo . from_location loc in let kind = ( pos , mode ) in warning_if_forced_inlined ~ loc ~ attribute " Function infor...
let strengthen_approx appl approx = match approx_ulam appl with ( Value_const _ ) as intapprox -> intapprox | _ -> approx
let check_constant_result ulam approx = match approx with Value_const c when is_pure ulam -> make_const c | Value_global_field ( id , i ) when is_pure ulam -> begin match ulam with | Uprim ( P . Pfield _ , [ Uprim ( P . Pread_symbol _ , _ , _ ) ] , _ ) -> ( ulam , approx ) ...
let sequence_constant_expr ulam1 ( ulam2 , approx2 as res2 ) = if is_pure ulam1 then res2 else ( Usequence ( ulam1 , ulam2 ) , approx2 )
let global_approx = ref ( [ ] || : value_approximation array )
let function_nesting_depth = ref 0
let close_approx_var { fenv ; cenv } id = let approx = try V . Map . find id fenv with Not_found -> Value_unknown in match approx with Value_const c -> make_const c | approx -> let subst = try V . Map . find id cenv with Not_found -> Uvar id in ( subst , approx )
let close_var env id = let ( ulam , _app ) = close_approx_var env id in ulam
let rec close ( { backend ; fenv ; cenv ; mutable_vars } as env ) lam = let module B = ( val backend : Backend_intf . S ) in match lam with | Lvar id -> close_approx_var env id | Lconst cst -> let str ( ? shared = true ) cst = let name = Compilenv . new_structured_constant cst ~ sh...
let collect_exported_structured_constants a = let rec approx = function | Value_closure ( _ , fd , a ) -> approx a ; begin match fd . fun_inline with | Some ( _ , u ) -> ulam u | None -> ( ) end | Value_tuple ( _ , a ) -> Array . iter approx a | Value_const c -> const c | V...
let reset ( ) = global_approx := [ ] ; || function_nesting_depth := 0