text
stringlengths
12
786k
let print_file_dependencies ( source_file , kind , extracted_deps , pp_deps ) = if ! raw_dependencies then begin print_raw_dependencies source_file extracted_deps end else match kind with | ML -> print_ml_dependencies source_file extracted_deps pp_deps | MLI -> print_mli_dependencies source_file extract...
let ml_file_dependencies source_file = let parse_use_file_as_impl lexbuf = let f x = match x with | Ptop_def s -> s | Ptop_dir _ -> [ ] in List . flatten ( List . map f ( Parse . use_file lexbuf ) ) in let ( extracted_deps , ( ) ) = read_parse_and_extract parse_use_file_as_impl Depe...
let mli_file_dependencies source_file = let ( extracted_deps , ( ) ) = read_parse_and_extract Parse . interface Depend . add_signature ( ) Pparse . Signature source_file in files := ( source_file , MLI , extracted_deps , ! Depend . pp_deps ) :: ! files
let process_file_as process_fun def source_file = Compenv . readenv ppf ( Before_compile source_file ) ; load_path := [ ] ; let cwd = if ! nocwd then [ ] else [ Filename . current_dir_name ] in List . iter add_to_load_path ( ( ! Compenv . last_include_dirs @ ! Clflags . include_...
let process_file source_file ~ ml_file ~ mli_file ~ def = if List . exists ( Filename . check_suffix source_file ) ! ml_synonyms then process_file_as ml_file def source_file else if List . exists ( Filename . check_suffix source_file ) ! mli_synonyms then process_file_as mli_file def source_file e...
let file_dependencies source_file = process_file source_file ~ def ( ) : ~ ml_file : ml_file_dependencies ~ mli_file : mli_file_dependencies
let file_dependencies_as kind = match kind with | ML -> process_file_as ml_file_dependencies ( ) | MLI -> process_file_as mli_file_dependencies ( )
let sort_files_by_dependencies files = let h = Hashtbl . create 31 in let worklist = ref [ ] in let files = List . map ( fun ( file , file_kind , deps , pp_deps ) -> let modname = String . capitalize_ascii ( Filename . chop_extension ( Filename . basename file ) ) in let key = ...
let rec dump_map s0 ppf m = let open Depend in String . Map . iter ( fun key ( Node ( s1 , m ' ) ) -> let s = String . Set . diff s1 s0 in if String . Set . is_empty s then Format . fprintf ppf " @ [ @< hv2 > module % s : sig % a ; @< 1 - 2 > end ] " @ key ( dump_m...
let process_ml_map = read_parse_and_extract Parse . implementation Depend . add_implementation_binding String . Map . empty Pparse . Structure
let process_mli_map = read_parse_and_extract Parse . interface Depend . add_signature_binding String . Map . empty Pparse . Signature
let parse_map fname = map_files := fname :: ! map_files ; let old_transp = ! Clflags . transparent_modules in Clflags . transparent_modules := true ; let ( deps , m ) = process_file fname ~ def ( : String . Set . empty , String . Map . empty ) ~ ml_file : process_ml_map ~ mli_fi...
type dep_arg = | Map of Misc . filepath | Src of Misc . filepath * file_kind option
let process_dep_arg = function | Map file -> parse_map file | Src ( file , None ) -> file_dependencies file | Src ( file , ( Some file_kind ) ) -> file_dependencies_as file_kind file
let process_dep_args dep_args = List . iter process_dep_arg dep_args
let print_version ( ) = Format . printf " ocamldep , version % s . " @ Sys . ocaml_version ; exit 0 ; ; ;
let print_version_num ( ) = Format . printf " % s . " @ Sys . ocaml_version ; exit 0 ; ; ;
let run_main argv = let dep_args_rev : dep_arg list ref = ref [ ] in let add_dep_arg f s = dep_args_rev := ( f s ) :: ! dep_args_rev in Clflags . classic := false ; Compenv . readenv ppf Before_args ; Clflags . reset_arguments ( ) ; Clflags . add_arguments __LOC__ [ " - absname "...
let main ( ) = run_main Sys . argv
let main_from_option ( ) = if Sys . argv . ( 1 ) <> " - depend " then begin Printf . eprintf " Fatal error : argument - depend must be used as first argument . \ n " ; %! exit 2 ; end ; let args = Array . concat [ [ | Sys . argv . ( 0 ) ^ " - depend " ] ; ...
let cpt = ref 0
let tot_time = ref 0 .
let measure_time f s = let t0 = Unix . gettimeofday ( ) in let a = f ( ) in let t1 = Unix . gettimeofday ( ) in Printf . printf " % s time % d : % Fs \ n " %! s ! cpt ( t1 . - t0 ) ; tot_time := ! tot_time . + ( t1 . - t0 ) ; incr cpt ; a ; ;
let devices = measure_time Spoc . Devices . init " init "
let width = ref 512l ; ;
let height = ref 512l ; ;
let max_iter = ref 512l ; ;
let zoom = ref 1 .
let shiftx = ref 0l
let shifty = ref 0l ; ;
let recompile = ref false
let simple = ref true
let mandelbrot_recompile = kern img ->
let normalize = fun x y -> x . * x . + y . * y in
let y = thread_idx_y + ( block_idx_y * block_dim_y ) in
let x = thread_idx_x + ( block_idx_x * block_dim_x ) in return ( ) ; ) ; let x0 = ( x + @ shiftx ) in let y0 = ( y + @ shifty ) in let mutable cpt = 0 in let mutable x1 = 0 . in let mutable y1 = 0 . in let mutable x2 = 0 . in let mutable y2 = 0 . in let a = 4 . . ...
let mandelbrot = kern img shiftx shifty zoom -> let open Std in let y = thread_idx_y + ( block_idx_y * block_dim_y ) in let x = thread_idx_x + ( block_idx_x * block_dim_x ) in ( if ( y >= @ height ) || ( x >= @ width ) then return ( ) ; ) ; let x0 = ( x + shiftx ) in let y...
let mandelbrot_double = kern img shiftx shifty zoom -> let open Std in
let normalize = fun x y -> x . * x . + y . * y in let open Math . Float64 in let y = thread_idx_y + ( block_idx_y * block_dim_y ) in let x = thread_idx_x + ( block_idx_x * block_dim_x ) in ( if ( y >= @ height ) || ( x >= @ width ) then return ( ) ; ) ; let x0 = ( ...
let cpu_compute img width height = for x = 0 to width - 1 do for y = 0 to height - 1 do let x0 = x in let y0 = y in let cpt = ref 0l in let x1 = ref 0 . in let y1 = ref 0 . in let x2 = ref 0 . in let y2 = ref 0 . in let a = 4 . . * ( ( Pervasives . float x0 ) . / ( Perva...
let dev = ref devices . ( 0 ) ; ;
let auto_transfers = ref true ; ;
let bench = ref ( false , 0 ) ; ;
let prof = ref false
let get_min ar = Spoc . Mem . to_cpu ar ( ) ; let min = ref ! max_iter in for i = 0 to ( Spoc . Vector . length ar - 1 ) do if ( Int32 . to_int ( Spoc . Mem . unsafe_get ar i ) ) > 1 then if ( ( Spoc . Mem . unsafe_get ar i ) ) < ! min then done ; ! min
let couleur n = if n = ! max_iter then Graphics . rgb 196 200 200 else let f n = let n = Int32 . to_int n in let i = Pervasives . float n in int_of_float ( 255 . . * ( 0 . 5 . + 0 . 5 . * sin ( i . * 0 . 1 ) ) ) in Graphics . rgb ( f ( Int32 . add n 32l ) ...
let main_mandelbrot ( ) = let arg1 = ( " - device " , Arg . Int ( fun i -> dev := devices . ( i ) ) , and arg2 = ( " - height " , Arg . Int ( fun i -> height := Int32 . of_int i ) , and arg3 = ( " - width " , Arg . Int ( fun i -> width := Int32 . of...
let measure_time f = let t0 = Unix . gettimeofday ( ) in let a = f ( ) in let t1 = Unix . gettimeofday ( ) in Printf . printf " time % d : % Fs \ n " %! ! cpt ( t1 . - t0 ) ; tot_time := ! tot_time . + ( t1 . - t0 ) ; incr cpt ; a ; ;
let _ = Printf . printf " % s \ n " ( " Interactive commands \ n " ^ ) ; measure_time ( main_mandelbrot ) ; Printf . printf " Total_time : % g \ n " %! ! tot_time ; ;
kernel mandelbrot : Spoc . Vector . vint32 -> int -> int -> int -> int -> int -> unit = " kernels / Mandelbrot2 " " mandelbrot "
let cpt = ref 0 ; ;
let tot_time = ref 0 .
let mesure_time f = let t0 = Unix . gettimeofday ( ) in let a = f ( ) in Printf . printf " temps % d : % F \ n " %! ! cpt ( t1 . - t0 ) ; a ; ;
let mesure_time f = f ( ) ; ;
let dev1 = ref devices . ( 0 ) ; ;
let dev2 = ref devices . ( 1 ) ; ;
let auto_transfers = ref true ; ;
let largeur = ref 800 ; ;
let hauteur = ref 800 ; ;
let max_iter = ref 500 ; ;
let b_iter = mesure_time ( fun ( ) -> Spoc . Vector . create Spoc . Vector . int32 ( ( ! largeur ) ( *! hauteur ) ) ) ; ;
let img = mesure_time ( fun ( ) -> Array . make_matrix ! largeur ! hauteur Graphics . black ) ; ;
let couleur n = if n = ! max_iter then Graphics . black else let f n = Graphics . rgb 0 ( f ( n + 16 ) ) ( f n )
let main ( ) = let arg0 = ( " - device1 " , Arg . Int ( fun i -> dev1 := devices . ( i ) ) , " number of the device [ 0 ] " ) and arg1 = ( " - device2 " , Arg . Int ( fun i -> dev2 := devices . ( i ) ) , " number of the device [ 0 ] " ) and ...
let mesure_time f = let t0 = Unix . gettimeofday ( ) in let a = f ( ) in Printf . printf " temps % d : % F \ n " %! ! cpt ( t1 . - t0 ) ; a ; ;
let width = ref 1024l ; ;
let height = ref 1024l ; ;
let max_iter = ref 10000l ; ;
let mandelbrot = kern img -> let open Std in let y = thread_idx_y + ( block_idx_y * block_dim_y ) in let x = thread_idx_x + ( block_idx_x * block_dim_x ) in if ( y < ! height ) && ( x < ! width ) then begin let x0 = x in let y0 = y in let mutable cpt = 0 in let mutable x1 = 0 . in l...
let cpu_compute img width height = for x = 0 to width - 1 do for y = 0 to height - 1 do let x0 = x in let y0 = y in let cpt = ref 0l in let x1 = ref 0 . in let y1 = ref 0 . in let x2 = ref 0 . in let y2 = ref 0 . in let a = 4 . . * ( ( float x0 ) . / ( float width ) ) ...
let append_text e s = Dom . appendChild e ( document ## createTextNode ( Js . string s ) )
let button action = let b = createInput ~ _type ( : Js . string " button " ) document in b ## value <- ( Js . string " Go " ) ; b ## onclick <- handler action ; b
let measure_time s f = let t0 = Unix . gettimeofday ( ) in let a = f ( ) in let t1 = Unix . gettimeofday ( ) in Printf . printf " Time % s : % Fs \ n " %! s ( t1 . - t0 ) ; a ; ;
let color n = if n = Int32 . to_int ! max_iter then ( 196 , 200 , 200 ) else let f n = let i = float n in int_of_float ( 255 . . * ( 0 . 5 . + 0 . 5 . * sin ( i . * 0 . 1 ) ) ) in ( ( f ( n + 32 ) ) , ( f ( n + 16 ) ) , ( f n ) )
let compute devid devs data imageData c = let dev = devs . ( devid ) in Printf . printf " Will use device : % s " ! ( dev ) . Spoc . Devices . general_info . Spoc . Devices . name ; let gpu_vect = Spoc . Vector . create Vector . int32 ( Int32 . to_int ( Int32 . mul ! w...
let f select_devices devs data imageData c = ( fun _ -> let select = select_devices ## selectedIndex + 0 in compute select devs data imageData c ; Js . _true ) ; ;
let newLine _ = Dom_html . createBr document
let nodeJsText t = let sp = Dom_html . createSpan document in Dom . appendChild sp ( document ## createTextNode ( t ) ) ; sp
let nodeText t = nodeJsText ( Js . string t )
let go _ = let body = Js . Opt . get ( document ## getElementById ( Js . string " section1 " ) ) ( fun ( ) -> assert false ) in Dom . appendChild body ( newLine ( ) ) ; let select_devices = createSelect document in Dom . appendChild body ( nodeText " Choose a computing ...
let _ = window ## onload <- handler go
let escape_symbols part = let buf = Buffer . create 16 in let was_hex_last = ref false in let handle_char = function | ( ' A ' . . ' Z ' | ' a ' . . ' z ' | ' 0 ' . . ' 9 ' | ' _ ' ) as c -> if ! was_hex_last then Buffer . add_string buf " __ " ; Buff...
type expression = | String of string | Dot of expression * string
type cpp_name = | Simple of string | Scoped of cpp_name list | Templated of string * template_arg list | Cpp_name of cpp_name | Expression of expression
let mangle_cpp name = let with_length s = let s = escape_symbols s in Printf . sprintf " % d % s " ( String . length s ) s in let rec mangle_expression = function | String s -> with_length s | Dot ( e , name ) -> Printf . sprintf " dt % s % s " ( mangle_expression e ) ( with_le...
let file_template_arg file = let filename = Filename . basename file in match String . split_on_char ' . ' filename with | [ ] -> Misc . fatal_error " Empty split " | hd :: tl -> let expr = List . fold_left ( fun e x -> Dot ( e , x ) ) ( String hd ) tl in Expression expr
let name_op = function | " " + -> " PLUS " | " " ++ -> " PLUSPLUS " | " . " + -> " PLUSDOT " | " " += -> " PLUSEQ " | " " - -> " MINUS " | " . " - -> " MINUSDOT " | " " * -> " STAR " | " " % -> " PERCENT " | " " = -> " ...
let build_location_info loc = let loc = Debuginfo . Scoped_location . to_location loc in let file , line , startchar = Location . get_pos_info loc . loc_start in let endchar = loc . loc_end . pos_cnum - loc . loc_start . pos_bol in let line_str = Printf . sprintf " ln_ % d " line in let...
let convert_identifier str = match String . split_on_char ' ' ' \ str with | [ ] -> Misc . fatal_error " empty split " | [ s ] -> Simple s | parts -> let s = String . concat " _Q " parts in Templated ( s , [ Cpp_name ( Simple " quoted " ) ] )
let convert_closure_id id loc = if String . begins_with id " anon_fn [ " then let _init , stamp = String . split_last_exn id ' _ ' in Templated ( " anon_fn_ " ^ stamp , build_location_info loc ) else match id . [ 0 ] with | ' A ' . . ' Z ' | ' a ' . . ' z ' ...
let convert_scope scope = let n = String . length scope in if String . equal scope " ( fun ) " then Templated ( " anon_fn " , [ ] ) else if n > 2 && String . get scope 0 = ' ( ' && String . get scope ( n - 1 ) = ' ) ' then let op = String . sub scope 1 ( n ...
let list_of_scopes scopes = let scope_str = Debuginfo . Scoped_location . string_of_scopes scopes in String . split_on_chars scope_str [ ' . ' ; ' ' ] #
let scope_matches_closure_id scope closure_id = String . equal scope " ( fun ) " || String . begins_with closure_id scope || String . length scope >= 3 && String . begins_with closure_id ( String . sub scope 1 ( String . length scope - 2 ) )
let module_and_scopes ~ unitname loc id = match ( loc : Debuginfo . Scoped_location . t ) with | Loc_known { loc = _ ; scopes } -> ( let scopes = list_of_scopes scopes in let scopes = match List . rev scopes with | [ ] -> Misc . fatal_errorf " No location - % s % s " unitname i...
let remove_prefix ~ prefix str = let n = String . length prefix in if String . begins_with str prefix then String . sub str n ( String . length str - n ) else str
let fun_symbol ~ unitname ~ loc ~ id = let unitname = remove_prefix ~ prefix " : caml " unitname in let top_level_module , sub_scopes = module_and_scopes ~ unitname loc id in let namespace_parts name = String . split_on_string name " __ " |> List . map ( fun part -> Simple part ) in let p...
module type OrderedType = sig type t val compare : t -> t -> int end
module type S = sig type key type ' !+ a t val empty : ' a t val is_empty : ' a t -> bool val mem : key -> ' a t -> bool val add : key -> ' a -> ' a t -> ' a t val update : key -> ( ' a option -> ' a option ) -> ' a t -> ' a t val singleton : key -> ' a -> ' a t val rem...
module Make ( Ord : OrderedType ) = struct type key = Ord . t type ' a t = Empty | Node of { l ' : a t ; v : key ; d ' : a ; r ' : a t ; h : int } let height = function Empty -> 0 | Node { h } -> h let create l x d r = let hl = height l and hr = height r in Node { l ; ...
type ' a ref = { mutable contents : ' a }