text
stringlengths
0
601k
let exchange ( v : ( float , Bigarray . float32_elt ) Spoc . Vector . vector ) i j : unit = let t : float = v . [ < i ] > in v . [ < i ] > <- v . [ < j ] ; > v . [ < j ] > <- t ; ;
let rec sortup v m n : unit = if n <> 1 then begin sortup v m ( n / 2 ) ; sortdown v ( m + n / 2 ) ( n / 2 ) ; mergeup v m ( n / 2 ) ; end m n : unit = if n <> 1 then begin sortup v m ( n / 2 ) ; sortdown v ( m + n / 2 ) ( n / 2 ) ; mergedown v m ( n / 2 ) ; end ( m : int ) ( n : int ) : unit = if n <> 0 then begin for...
let cpt = ref 0
let tot_time = ref 0 .
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 ) ; tot_time := ! tot_time . + ( t1 . - t0 ) ; incr cpt ; a ; ;
let nearest_pow2 i = let rec aux acc = let res = acc * 2 in if res < i then aux res else acc in let r = aux 1 in if r <> i then Printf . printf " Changed size value to a power of two ( % d -> % d ) \ n " i r ; r
let ( ) = let devid = ref 0 and size = ref 1024 and check = ref true and compare = ref true in let arg1 = ( " - device " , Arg . Int ( fun i -> devid := i ) , and arg2 = ( " - size " , Arg . Int ( fun i -> size := nearest_pow2 i ) , and arg3 = ( " - bench " , Arg . Bool ( fun b -> compare := b ) , and arg4 = ( " - chec...
let gpu_bitonic = kern v j k -> let open Std in let i = thread_idx_x + block_dim_x * block_idx_x in let ixj = Math . xor i j in let mutable temp = 0 . in if ixj >= i then begin if ( Math . logical_and i k ) = 0 then ( if v . [ < i ] > . > v . [ < ixj ] > then ( temp := v . [ < ixj ] ; > v . [ < ixj ] > <- v . [ < i ] ;...
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 text name default cols = let b = createInput ~ _type ( : Js . string " text " ) document in b ## value <- ( Js . string default ) ; b ## size <- 4 ; b
let cpt = ref 0
let tot_time = ref 0 .
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 ) ; tot_time := ! tot_time . + ( t1 . - t0 ) ; incr cpt ; a ; ;
let compute size devid devs = let dev = devs . ( devid ) in Printf . printf " Will use device : % s to sort % d floats \ n " %! ( dev ) . Spoc . Devices . general_info . Spoc . Devices . name size ; let gpu_vect = Spoc . Vector . create Vector . float32 size and base_vect = Spoc . Vector . create Vector . float32 size ...
let pow2 n = let rec aux acc n = if n = 1 then acc else aux ( acc * 2 ) ( n - 1 ) in aux 2 n
let f size_text select_devices devs = ( fun _ -> let size = pow2 ( int_of_string ( Js . to_string size_text ## value ) ) in let select = select_devices ## selectedIndex + 0 in compute size select devs ; 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 devs = Devices . init ~ only : Devices . OpenCL ( ) in let body = Js . Opt . get ( document ## getElementById ( Js . string " section1 " ) ) ( fun ( ) -> assert false ) in Dom . appendChild body ( nodeText " This sample computes a bitonic sort over a vector of float " ) ; Dom . appendChild body ( newLine...
let _ = window ## onload <- handler go
let number_of_data_bytes ( t : t ) = Bits0 . number_of_data_bytes t
module Expert = struct let unsafe_underlying_repr ( t : t ) = ( t :> Bytes . t ) let offset_for_data = 8 end
module Mutable = struct include Bits0 let is_empty a = width a = 0 let of_constant t = t let to_constant t = t let to_string t = Constant . to_binary_string t let to_int t = Constant . to_int t let copy ~ src ~ dst = let words = words src in for i = 0 to words - 1 do unsafe_set_int64 dst i ( unsafe_get_int64 src i ) do...
let to_int x = Constant . to_int x
let to_int32 x = Constant . to_int32 x
let zero w = Bits0 . create w
let pp fmt t = Caml . Format . fprintf fmt " % s " ( to_bstr t )
module _ = Pretty_printer . Register ( struct type nonrec t = Bits0 . t let module_name = " Hardcaml . Bits " let to_string = to_bstr end )
module T = struct open Bin_prot . Std module For_sexp = struct type t = { width : int ; data : bytes } [ @@ deriving sexp ] end type t = bytes [ @@ deriving compare , bin_io ] let width t = Int64 . to_int_trunc ( Bytes . unsafe_get_int64 t 0 ) let offset_for_data = 8 let sexp_of_t ( t : t ) = For_sexp . sexp_of_t { wid...
module Comparable = Comparable . Make ( T )
let words_of_width width = ( width + bits_per_word - 1 ) lsr log_bits_per_word
let bytes_of_width width = words_of_width width lsl shift_bytes_to_words
let words t = words_of_width ( width t )
let number_of_data_bytes t = Bytes . length t - 8
let create width = let bytes = Bytes . make ( ( words_of_width width + 1 ) lsl shift_bytes_to_words ) ' \ 000 ' in Bytes . unsafe_set_int64 bytes 0 ( Int64 . of_int width ) ; bytes ; ;
let empty = create 0
let unsafe_get_byte ( t : t ) i = Bytes . unsafe_get t ( offset_for_data + i )
let unsafe_get_int64 ( t : t ) i = Bytes . unsafe_get_int64 t ( ( i lsl shift_bytes_to_words ) + offset_for_data ) ; ;
let unsafe_set_int64 ( t : t ) i x = Bytes . unsafe_set_int64 t ( ( i lsl shift_bytes_to_words ) + offset_for_data ) x ; ;
let mask ( t : t ) = let width = width t in let bits = width land width_mask in if bits <> 0 then ( let mask = Int64 . ( lsr ) ( - 1L ) ( 64 - bits ) in let word_pos = ( width - 1 ) lsr log_bits_per_word in let x = Int64 . ( land ) ( unsafe_get_int64 t word_pos ) mask in unsafe_set_int64 t word_pos x ) ; ;
let init_byte ~ width ~ f = let t = create width in let num_bytes = words_of_width width lsl shift_bytes_to_words in for i = 0 to num_bytes - 1 do Bytes . unsafe_set t ( i + offset_for_data ) ( f i ) done ; mask t ; t ; ;
let init_int64 ~ width ~ f = let t = create width in let num_words = words_of_width width in for i = 0 to num_words - 1 do unsafe_set_int64 t i ( f i ) done ; mask t ; t ; ;
module type Bits = sig type t [ @@ deriving compare , sexp_of ] include Comb . S with type t := t include Comparator . S with type t := t val number_of_data_bytes : t -> int val unsafe_get_int64 : t -> int -> int64 val unsafe_set_int64 : t -> int -> int64 -> unit module Expert : sig val unsafe_underlying_repr : t -> by...
let ( mod ) = Caml . ( mod )
let nbits = Int . num_bits - 1
let words bits = ( bits + nbits - 1 ) / nbits
let word_index bit = bit / nbits
let m = - 1 lsr 1
let mask_bits n = if n = 0 then m else m lsr ( nbits - n )
let mask_bit n = 1 lsl n
let bo2 = nbits / 2
let mask_lo = mask_bits bo2
let mask_hi = mask_bits bo2 lsl bo2
let half_lo x = x land mask_lo
let half_hi x = ( x land mask_hi ) lsr bo2
let cbit = mask_bit bo2
let create_words bits = Array . create ~ len ( : words bits ) 0
let words_of_int bits i = let b = create_words bits in b . ( 0 ) <- i land m ; b ; ;
let get_word a n = a . ( n )
let set_word a n w = a . ( n ) <- w land m
module type Integer = sig include Int . S val nbits : int end
let convert_abits_and_string ( type t ) ( module X : Integer with type t = t ) = let ( . | ) = X . ( lor ) in let ( . & ) = X . ( land ) in let ( . << ) = X . shift_left in let one = X . of_int_exn 1 in let of_bstr b = let width = String . length b in let words = ( width + X . nbits - 1 ) / X . nbits in let a = Array ....
module XInt = struct include Int let nbits = num_bits - 1 end
let abits_int_of_bstr , bstr_of_abits_int = convert_abits_and_string ( module XInt )
module T = struct type t = int array * int [ @@ deriving compare ] let equal = [ % compare . equal : t ] let empty = create_words 0 , 0 let width = snd let is_empty ( _ , width ) = width = 0 let to_string x = bstr_of_abits_int ~ width ( : width x ) ( fst x ) let to_int ( data , width ) = if width <= nbits then data . (...
module Mutable = struct module T = struct type t = T . t [ @@ deriving compare ] let equal = T . equal let empty = T . empty let is_empty = T . is_empty let width = T . width let data s = fst s let to_string = T . to_string let to_int = T . to_int let to_bstr = T . to_bstr let mask s = let width = width s in let top_wo...
let pp fmt t = Caml . Format . fprintf fmt " % s " ( to_bstr t )
module PP = Pretty_printer . Register ( struct type nonrec t = t let module_name = " Hardcaml . Bits " let to_string = to_bstr end )
type t = { mutable vhd : IO . fd Vhd_format . F . Vhd . t option ; info : info ; id : string ; }
let connect path = Lwt_unix . LargeFile . stat path >>= fun _ -> Lwt . catch ( fun ( ) -> Lwt_unix . access path [ Lwt_unix . W_OK ] >>= fun ( ) -> return true ) ( fun _ -> return false ) >>= fun read_write -> Vhd_IO . openchain path read_write >>= fun vhd -> let open Vhd_format . F in let sector_size = 512 in let size...
let disconnect t = match t . vhd with | None -> return ( ) | Some vhd -> Vhd_IO . close vhd >>= fun ( ) -> t . vhd <- None ; return ( )
let get_info t = return t . info
let to_sectors bufs = let rec loop acc remaining = if Cstruct . len remaining = 0 then List . rev acc else let available = min 512 ( Cstruct . len remaining ) in loop ( Cstruct . sub remaining 0 available :: acc ) ( Cstruct . shift remaining available ) in List . concat ( List . map ( loop [ ] ) bufs )
let forall_sectors f offset bufs = let rec one offset = function | [ ] -> return ( ) | b :: bs -> f offset b >>= fun ( ) -> one ( Int64 . succ offset ) bs in one offset ( to_sectors bufs )
let zero = let buf = Cstruct . create 512 in for i = 0 to Cstruct . len buf - 1 do Cstruct . set_uint8 buf i 0 done ; buf
let read t offset bufs = match t . vhd with | None -> return ( Rresult . R . error ` Disconnected ) | Some vhd -> forall_sectors ( fun offset sector -> ( Vhd_IO . read_sector vhd offset sector >>= function | false -> Cstruct . blit zero 0 sector 0 512 ; return ( ) | true -> return ( ) ) >>= fun ( ) -> return ( ) ) offs...
let write t offset bufs = match t . vhd with | None -> return ( Rresult . R . error ` Disconnected ) | Some vhd -> Vhd_IO . write vhd offset bufs >>= fun ( ) -> return ( Rresult . R . ok ( ) )
let mk_bmd_concept_with_loc desc loc = { concept_desc = desc ; concept_loc = loc ; }
let mk_bmd_concept cname1 cname2 ctype = mk_bmd_concept_with_loc ( cname1 , cname2 , ctype ) ( Parsing . symbol_start_pos ( ) , Parsing . symbol_end_pos ( ) )
let mk_bmd_type_with_loc desc loc = { type_desc = desc ; type_loc = loc ; }
let mk_bmd_type desc = mk_bmd_type_with_loc desc ( Parsing . symbol_start_pos ( ) , Parsing . symbol_end_pos ( ) )
let mk_bmd_string ( ) = mk_bmd_type BT_string
let mk_bmd_int ( ) = mk_bmd_type BT_int
let mk_bmd_real ( ) = mk_bmd_type BT_real
let mk_bmd_boolean ( ) = mk_bmd_type BT_boolean
let mk_bmd_date ( ) = mk_bmd_type BT_date
let mk_bmd_duration ( ) = mk_bmd_type BT_duration
let mk_bmd_rec fields = mk_bmd_type ( BT_rec fields )
let mk_bmd_enum values = mk_bmd_type ( BT_enum values )
let mk_bmd_ref cname = mk_bmd_type ( BT_ref cname )
let mk_bmd_schema_with_loc desc loc = { schema_desc = desc ; schema_loc = loc }
let mk_bmd_schema desc = mk_bmd_schema_with_loc desc ( Parsing . symbol_start_pos ( ) , Parsing . symbol_end_pos ( ) )
let airplane = mk_bmd_concept " airplane " ( Some " business entity " ) ( mk_bmd_rec [ ( " airplane id " , mk_bmd_string ( ) ) ; ( " average engine pressure ratio " , mk_bmd_int ( ) ) ; ( " average engine rpm " , mk_bmd_int ( ) ) ; ( " engine warnings " , mk_bmd_int ( ) ) ; ] )
let airplane_event = mk_bmd_concept " airplane event " ( Some " business event " ) ( mk_bmd_rec [ ( " aircraft id " , mk_bmd_string ( ) ) ; ( " engine " , mk_bmd_ref " engine " ) ; ] )
let engine = mk_bmd_concept " engine " None ( mk_bmd_rec [ ( " pressure ratio " , mk_bmd_int ( ) ) ; ( " rpm " , mk_bmd_int ( ) ) ; ] )
let airline_schema = mk_bmd_schema [ airplane ; airplane_event ; engine ; ]
let account_concept = mk_bmd_concept " account " ( Some " business entity " ) ( mk_bmd_rec [ ( " id " , mk_bmd_string ( ) ) ; ( " status " , mk_bmd_ref " account status " ) ; ] )
let account_status_concept = mk_bmd_concept " account status " None ( mk_bmd_enum [ " Excellent " ; " Good " ; " Fair " ; " Poor " ; " Risky " ; ] )