text
stringlengths
12
786k
let kb_complete greater complete_rules rules = let n = check_rules complete_rules and eqs = List . map ( fun rule -> ( rule . lhs , rule . rhs ) ) rules in let completed_rules = kb_completion greater n complete_rules [ ] ( n , n ) eqs in print_string " Canonical set found " ; : pri...
let geom_rules = [ { number = 1 ; numvars = 1 ; lhs = Term ( " " , [ ( * Term ( " U " , [ ] ) ) ; ( Var 1 ) ] ) ; rhs = Var 1 } ; { number = 2 ; numvars = 1 ; lhs = Term ( " " , [ ( * Term ( " I " , [ ( Var 1 ) ] ) ...
let group_rank = function " U " -> 0 | " " * -> 1 | " I " -> 2 | " B " -> 3 | " C " -> 4 | " A " -> 5 | _ -> assert false
let group_precedence op1 op2 = let r1 = group_rank op1 and r2 = group_rank op2 in if r1 = r2 then Equal else if r1 > r2 then Greater else NotGE
let group_order = rpo group_precedence lex_ext
let greater pair = match group_order pair with Greater -> true | _ -> false
let _ = for i = 1 to 20 do kb_complete greater [ ] geom_rules done
type kernel ( ' a , ' b ) Vector . vector -> ( ' c , ' d ) Vector . vector = " % identity "
type ( ' a , ' b ) kernelArgs = | VChar of ( ' a , ' b ) Vector . vector | VFloat32 of ( ' a , ' b ) Vector . vector | VFloat64 of ( ' a , ' b ) Vector . vector | VComplex32 of ( ' a , ' b ) Vector . vector | VInt32 of ( ' a , ' b ) Vector . ve...
type block = { mutable blockX : int ; mutable blockY : int ; mutable blockZ : int }
type grid = { mutable gridX : int ; mutable gridY : int ; mutable gridZ : int }
module Cuda = struct type cuda_extra external cuda_create_extra : int -> cuda_extra = " spoc_cuda_create_extra " external cuda_compile : string -> string -> Devices . generalInfo -> kernel = " spoc_cuda_compile " external cuda_debug_compile : string -> string -> Devices . generalInfo -> kernel ...
module OpenCL = struct external opencl_compile : string -> string -> Devices . generalInfo -> kernel = " spoc_opencl_compile " external opencl_debug_compile : string -> string -> Devices . generalInfo -> kernel = " spoc_debug_opencl_compile " external opencl_load_param_vec : int ref -> kernel ...
let exec ( args : ( ' a , ' b ) kernelArgs array ) ( block , grid ) queue_id dev ( bin : kernel ) = match dev . Devices . specific_info with | Devices . CudaInfo cI -> let open Cuda in let cuFun = bin in let offset = ref 0 in let extra = cuda_create_extra ( Array . length args...
let compile_and_run ( dev : Devices . device ) ( ( block : block ) , ( grid : grid ) ) ? cached ( : c = false ) ? debug ( : d = false ) ? queue_id ( : q = 0 ) ker = snd ( fst ker ) ( block , grid ) c d q dev
let load_source path file ext = let kernelPath = path ^ Filename . dir_sep ^ file ^ ext in let src = ref " " in let ic = open_in kernelPath in ( try while true do src := ! src ^ input_line ic ^ " \ n " done with End_of_file -> ( ) ) ; close_in ic ; ! src object ( self ) val file_...
let run ( dev : Devices . device ) ( ( block : block ) , ( grid : grid ) ) ( k : ( ' a , ' b ) spoc_kernel ) ( args : ' a ) = k # run args ( block , grid ) 0 dev
let compile ( dev : Devices . device ) ( k : ( ' a , ' b ) spoc_kernel ) = k # compile ~ debug : false dev
let set_arg env i arg = env . ( i ) <- ( match Vector . kind arg with | Vector . Float32 _ -> VFloat32 arg | Vector . Char _ -> VChar arg | Vector . Float64 _ -> VFloat64 arg | Vector . Int32 _ -> VInt32 arg | Vector . Int64 _ -> VInt64 arg | Vector . Complex32 _ -> VComplex32 ...
let print i = if debug then Printf . printf " % s \ n " %! i
let expr_of_string = Syntax . Gram . parse_string Syntax . expr_eoi ; ;
let id = ref 0
let arg_string = ref " "
let arg_string2 = ref " "
let idx = ref 1
let create_new_var loc = let v = " spoc_var " ( ^ string_of_int ! id ) in let a = expr_of_string loc ( v ) in incr id ; a , v
let rec string_of_ident = function | <: ident < $ lid : s $ >> -> s | <: ident < $ uid : s $ >> -> s | <: ident < $ i1 . $$ i2 $ >> -> " acc_ " ^ ( string_of_ident i1 ) ^ " _ " ^ ( string_of_ident i2 ) | <: ident < $ i1 ( $$ i2 ) $ >> -> " app_ " ^ ( str...
let fst3 = fun ( x , y , z ) -> x
let snd3 = fun ( x , y , z ) -> y
let thrd3 = fun ( x , y , z ) -> z
let rec parse_ctyp = function | TyNil _ -> failwith " TyNil " ; | TyAli _ -> failwith " TyAli " ; | TyAny _ -> failwith " TyAny " ; | TyApp ( l , c1 , c2 ) as t -> let e , v = create_new_var l in [ ExTyc ( l , e , t ) ] , [ v ] , [ t ] | TyArr ( l , ...
let rec parseTyp t i = match t with | TyId ( _ , id ) when ( ( string_of_ident id ) = " char " ) -> incr idx ; arg_string := " Spoc . Kernel . Char " ^ i " ^ " ( ^! arg_string ) ; arg_string2 := i " ^ " ( ^! arg_string2 ) | TyId ( _ , id ) when ( ( s...
let rec parseInvTyp t i = match t with | TyId ( _ , id ) when ( String . compare ( string_of_ident id ) " char " ) = 0 -> incr idx ; arg_string := " Spoc . Kernel . Char " ^ i " ^ " ( ^! arg_string ) ; arg_string2 := i " ^ " ( ^! arg_string2 ) | TyId ( _ ...
let rec type_to_type t = match t with | TyId ( l , id ) when ( String . compare ( string_of_ident id ) " float64 " ) = 0 -> let _loc = l in ( <: ctyp < float ) >> | TyId ( l , id ) when ( String . compare ( string_of_ident id ) " acc_acc_Spoc_Vector_vfloat32 " ) =...
let rec concrete_type_to_type t = match t with | TyId ( l , id ) when ( String . compare ( string_of_ident id ) " float64 " ) = 0 -> let _loc = l in ( <: ctyp < float ) >> | TyId ( l , id ) when ( String . compare ( string_of_ident id ) " acc_acc_Spoc_Vector_vfloat32 "...
let gen_ktyp loc type_list = let l = List . map concrete_type_to_type type_list in let l = List . tl ( List . rev l ) in let l = List . rev l in match l with | [ ] -> assert false | [ x ] -> x | _ -> TyTup ( loc , Ast . tySta_of_list l )
let ident_of_string loc s = IdLid ( loc , s )
let gen_args loc type_list = id := 0 ; arg_string := " " ; let var_list = ref [ ] in let _loc = loc in let l = List . tl ( List . rev type_list ) in let l = List . rev l in let translate t = let nv = create_new_var loc in var_list :=! var_list @ [ nv ] ; PaTyc ( loc , ) in...
let first_vector = ref false
let relaxed _loc nv = if not ! first_vector then ( first_vector := true ; <: expr ( <$ ExId ( _loc , ) ) ) $>> else <: expr < Spoc . Kernel . relax_vector ( $ ExId ( _loc , ) ) $>>
let rec gen_inv_id t _loc nv = match t with | TyId ( l , id ) when ( ( string_of_ident id ) = " acc_acc_Spoc_Vector_vfloat32 " ) -> relaxed _loc nv | TyId ( l , id ) when ( ( string_of_ident id ) = " acc_acc_Spoc_Vector_vfloat64 " ) -> relaxed _loc nv | TyId ( l , id )...
let gen_inv_args loc type_list = id := 0 ; arg_string := " " ; let var_list = ref [ ] in first_vector := false ; let _loc = loc in let l = List . tl ( List . rev type_list ) in let l = List . rev l in let translate t = let nv = create_new_var loc in var_list :=! var_list @ [ nv ]...
let bigarray_set _loc var newval = match var with <: expr < Bigarray . Array1 . get $ arr $ $ c1 $ >> -> Some <: expr < Bigarray . Array1 . set $ arr $ $ c1 $ $ newval $ >> | <: expr < Bigarray . Array2 . get $ arr $ $ c1 $ $ c2 $ >> -> Some <: expr < Bigarray . Array2 . ...
let $ p1 $ = new $ lid : class_name ; ; $ StSem ( _loc , ] ] ; END
let idkern = ref 0
module Kirc_OpenCL = Gen . Generator ( Kirc_OpenCL )
module Kirc_Cuda = Gen . Generator ( Kirc_Cuda )
module Kirc_Profile = Gen . Generator ( Profile )
type extension = ExFloat32 | ExFloat64
type ( ' a , ' b , ' c ) kirc_kernel = { ml_kern : ' a ; body : Kirc_Ast . k_ext ; ret_val : Kirc_Ast . k_ext * ( ' b , ' c ) Vector . kind ; extensions : extension array }
type ( ' a , ' b , ' c , ' d ) kirc_function = { fun_name : string ; ml_fun : ' a ; funbody : Kirc_Ast . k_ext ; fun_ret : Kirc_Ast . k_ext * ( ' b , ' c ) Vector . kind ; fastflow_acc : ' d ; fun_extensions : extension array }
type ( ' a , ' b , ' c , ' d , ' e ) sarek_kernel = ( ' a , ' b ) spoc_kernel * ( ' c , ' d , ' e ) kirc_kernel
let constructors = ref [ ]
let opencl_head = " # define SAREK_VEC_LENGTH ( A ) sarek_ ## A ## _length \ n " ^ " float spoc_fadd ( float a , float b ) ; \ n " ^ " float spoc_fminus ( float a , float b ) ; \ n " ^ " float spoc_fmul ( float a , float b ) ; \ n " ^ " float spoc_fdiv ( floa...
let opencl_common_profile = " \ n /*********** PROFILER FUNCTIONS **************/\ n " ^ " # pragma OPENCL EXTENSION cl_khr_int64_extended_atomics : enable \ n " ^ " void spoc_atomic_add ( __global ulong * a , ulong b ) { atom_add ( a , ( ulong ) b ) ; } \ n " ^ " \ n ...
let opencl_profile_head = opencl_common_profile ^ " \ n \ void branch_analysis ( __global ulong * profile_counters , int eval , int \ counters ) { \ n \ \ \ n \ \ unsigned int threadIdxInGroup = \ n \ \ get_local_id ( 2 ) * get_local_size ( 0 ) * get_local_size ( 1 ) + \ ...
let opencl_profile_head_cpu = opencl_common_profile ^ " \ n \ void branch_analysis ( __global ulong * profile_counters , int eval , int \ counters ) { \ n \ \ \ n \ \ unsigned int threadIdxInGroup = \ n \ \ get_local_id ( 2 ) * get_local_size ( 0 ) * get_local_size ( 1 ) +...
let opencl_float64 = " # ifndef __FLOAT64_EXTENSION__ \ n " ^ " # define __FLOAT64_EXTENSION__ \ n " ^ " # if defined ( cl_khr_fp64 ) // Khronos extension available ?\ n " ^ " # pragma OPENCL EXTENSION cl_khr_fp64 : enable \ n " ^ " # elif defined ( cl_amd_fp64 ) // AMD exte...
let cuda_float64 = " # ifndef __FLOAT64_EXTENSION__ \ n " ^ " # define __FLOAT64_EXTENSION__ \ n " ^ " __device__ double spoc_dadd ( double a , double b ) { return ( a + b ) ; } \ n " ^ " __device__ double spoc_dminus ( double a , double b ) { return ( a - b ) ; ...
let cuda_head = " # define SAREK_VEC_LENGTH ( a ) sarek_ ## a ## _length \ n " ^ " # define FULL_MASK 0xffffffff \ n " ^ " __device__ float spoc_fadd ( float a , float b ) { return ( a + b ) ; } \ n " ^ " __device__ float spoc_fminus ( float a , float b ) { retu...
let cuda_profile_head = " \ n /*********** PROFILER FUNCTIONS **************/\ n " ^ " __device__ void spoc_atomic_add ( unsigned long long int * a , unsigned int \ b ) { atomicAdd ( a , b ) ; } \ n " ^ " __device__ __forceinline__ unsigned int get_laneid ( void ) { \ n \...
let new_var i = IdName ( " spoc_var " ^ string_of_int i )
let new_array n l t m = Arr ( n , l , t , m )
let var i s = IntId ( s , i )
let spoc_gen_kernel args body = Kern ( args , body )
let spoc_fun_kernel _a _b = ( )
let global_fun a = GlobalFun ( a . funbody , ( match snd a . fun_ret with | Vector . Int32 _ -> " int " | Vector . Float32 _ -> " float " | Vector . Custom _ -> ( match fst a . fun_ret with | CustomVar ( s , _ , _ ) -> " struct " ^ s ^ " _sarek " | _ -> as...
let seq a b = Seq ( a , b )
let app a b = App ( a , b )
let spoc_unit ( ) = Unit
let spoc_int a = Int a
let global_int_var a = GInt a
let global_float_var a = GFloat a
let global_float64_var a = GFloat64 a
let spoc_int32 a = Int ( Int32 . to_int a )
let spoc_float f = Float f
let spoc_double d = Double d
let spoc_int_id a = Int a
let spoc_float_id a = Float a
let spoc_plus a b = Plus ( a , b )
let spoc_plus_float a b = Plusf ( a , b )
let spoc_min a b = Min ( a , b )
let spoc_min_float a b = Minf ( a , b )
let spoc_mul a b = Mul ( a , b )
let spoc_mul_float a b = Mulf ( a , b )
let spoc_div a b = Div ( a , b )
let spoc_div_float a b = Divf ( a , b )
let spoc_mod a b = Mod ( a , b )
let spoc_ife a b c = Ife ( a , b , c )
let spoc_if a b = If ( a , b )
let spoc_match s e l = Match ( s , e , l )
let spoc_case i o e : case = ( i , o , e )
let spoc_do a b c d = DoLoop ( a , b , c , d )
let spoc_while a b = While ( a , b )
let params l = Params l
let spoc_id _i = Id " "
let spoc_constr t c params = Constr ( t , c , params )
let spoc_record t params = Record ( t , params )
let spoc_return k = Return k
let concat a b = Concat ( a , b )