package spoc
High-level GPGPU programming library for OCaml
Install
Dune Dependency
Authors
Maintainers
Sources
spoc_ppx-20210823.tbz
sha256=bdb247f51bce29609c0a6d7155a2f180b26cb7388489cf21961b4d6754a0eb03
sha512=1cdb37b214e06a32436d23308c4555f6ddefcd4674d73964faa4bb184f843c477c95ef719b8794ead32d12b1ee6a5b5541683ec76ab9e6b1c2e3f3d7371ba41c
doc/src/spoc.external_kernels/kernels_ext.ml.html
Source file kernels_ext.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
(****************************************************************************** * © Mathias Bourgoin, Université Pierre et Marie Curie (2011) * * Mathias.Bourgoin@gmail.com * * This software is a computer program whose purpose is to allow GPU * programming with the OCaml language. * * This software is governed by the CeCILL-B license under French law and * abiding by the rules of distribution of free software. You can use, * modify and/ or redistribute the software under the terms of the CeCILL-B * license as circulated by CEA, CNRS and INRIA at the following URL * "http://www.cecill.info". * * As a counterpart to the access to the source code and rights to copy, * modify and redistribute granted by the license, users are provided only * with a limited warranty and the software's author, the holder of the * economic rights, and the successive licensors have only limited * liability. * * In this respect, the user's attention is drawn to the risks associated * with loading, using, modifying and/or developing or reproducing the * software by the user in light of its specific status of free software, * that may mean that it is complicated to manipulate, and that also * therefore means that it is reserved for developers and experienced * professionals having in-depth computer knowledge. Users are therefore * encouraged to load and test the software's suitability as regards their * requirements in conditions enabling the security of their systems and/or * data to be ensured and, more generally, to use and operate it in the * same conditions as regards security. * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-B license and that you accept its terms. ******************************************************************************) open Camlp4.PreCast open Syntax open Ast exception Unbound_value of (Loc.t*string) exception Unbound_value2 of ((Loc.t*string)*Loc.t) (******************** debug tools **********************) let debug = false let print i = if debug then Printf.printf "%s\n%!" i (******************** external kernels **********************) 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_" ^ (string_of_ident i1) ^ "_" ^ (string_of_ident i2) | <:ident< $anti:_$ >> -> assert false 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 (*let l1 = parse_ctyp c1 and l2 =parse_ctyp c2 in*) [ExTyc (l, e, t)],[v],[t] (*failwith "TyApp";*) | TyArr (l,a,b) -> (*Printf.printf "TyArr\n";*) let l1 = parse_ctyp a and l2 =parse_ctyp b in ((fst3 l1)@(fst3 l2),(snd3 l1)@(snd3 l2),(thrd3 l1)@(thrd3 l2)) | TyCls _ -> failwith "TyCls"; | TyLab _ -> failwith "TyLab"; | (TyId (l,id)) as t -> let e,v =create_new_var l in begin match t with | TyId(_, id) when ((string_of_ident id) = "int32") -> ([ExTyc (l,e,TyId(l, ident_of_expr (expr_of_string l "int")))],[v],[t]) | TyId(_, id) when ((string_of_ident id) = "int64") -> ([ExTyc (l,e,TyId(l, ident_of_expr (expr_of_string l "int")))],[v],[t]) | TyId(_, id) when ((string_of_ident id) = "float32") -> ([ExTyc (l,e,TyId(l, ident_of_expr (expr_of_string l "float")))],[v],[t]) | TyId(_, id) when ((string_of_ident id) = "float64") -> ([ExTyc (l,e,TyId(l, ident_of_expr (expr_of_string l "float")))],[v],[t]) | _ -> ([ExTyc (l,e,t)],[v],[t]) end; | TyMan _ -> failwith "TyMan" | TyDcl _ -> failwith "TyDcl" | TyObj _ -> failwith "TyObj" | TyOlb _ -> failwith "TyOlb" | TyPol _ -> failwith "TyPol" | TyTypePol _ -> failwith "TyTypePol" | TyQuo _ -> failwith "TyQuo" | TyQuP _ -> failwith "TyQup" | TyQuM _ -> failwith "TyQum" | TyAnP _ -> failwith "TyAnP" | TyAnM _ -> failwith "TyAnM" | TyVrn _ -> failwith "TyVrn" | TyRec _ -> failwith "TyRec" | TyCol _ -> failwith "TyCol" | TySem _ -> failwith "TySem" | TyCom _ -> assert false | TySum _ -> assert false | TyOf _ -> assert false | TyAnd _ -> assert false | TyOr _ -> assert false | TyPrv _ -> assert false | TyMut _ -> assert false | TyTup _ -> assert false | TySta _ -> assert false | TyVrnEq _ -> assert false | TyVrnSup _ -> assert false | TyVrnInf _ -> assert false | TyVrnInfSup _ -> assert false | TyAmp _ -> assert false | TyPkg _ -> assert false | (TyAnt (l,s)) as _t -> failwith ("TyAnt : "^s) | _ -> failwith "parse_ctyp OUHLALA" 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 ((string_of_ident id) = "int") -> incr idx; arg_string := "Spoc.Kernel.Int32 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when ((string_of_ident id) = "int32") -> incr idx; arg_string := "Spoc.Kernel.Int32 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when ((string_of_ident id) = "int64") -> incr idx; arg_string := "Spoc.Kernel.Int64 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when ((string_of_ident id) = "float") -> incr idx; arg_string := "Spoc.Kernel.Float32 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when ((string_of_ident id) = "float32") -> incr idx; arg_string := "Spoc.Kernel.Float32 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when ((string_of_ident id) = "float64") -> incr idx; arg_string := "Spoc.Kernel.Float64 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when ((string_of_ident id) = "acc_acc_Spoc_Vector_vfloat32") -> incr idx; arg_string := "Spoc.Kernel.VFloat32 (Spoc.Kernel.relax_vector "^i^") "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when ((string_of_ident id) = "acc_acc_Spoc_Vector_vchar") -> incr idx; arg_string := "Spoc.Kernel.VChar (Spoc.Kernel.relax_vector "^i^") "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when ((string_of_ident id) = "acc_acc_Spoc_Vector_localvfloat32") -> incr idx; arg_string := "Spoc.Kernel.LocalFloat32 (Spoc.Kernel.relax_vector "^i^") "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when ((string_of_ident id) = "acc_acc_Spoc_Vector_vfloat64") -> incr idx; arg_string := "Spoc.Kernel.VFloat64 (Spoc.Kernel.relax_vector "^i^") "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when ((string_of_ident id) = "acc_acc_Spoc_Vector_vcomplex32") -> incr idx; arg_string := "Spoc.Kernel.VComplex32 (Spoc.Kernel.relax_vector "^i^") "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when ((string_of_ident id) = "acc_acc_Spoc_Vector_vint32") -> incr idx; arg_string := "Spoc.Kernel.VInt32 (Spoc.Kernel.relax_vector "^i^") "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when ((string_of_ident id) = "acc_acc_Spoc_Vector_vint64") -> incr idx; arg_string := "Spoc.Kernel.VInt64 (Spoc.Kernel.relax_vector "^i^") "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when ((string_of_ident id) = "acc_acc_Spoc_Vector_vbool") -> incr idx; arg_string := "Spoc.Kernel.VCustom (Spoc.Kernel.relax_vector "^i^") "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when ((string_of_ident id) = "acc_acc_Spoc_Vector_vcustom") -> incr idx; arg_string := "Spoc.Kernel.VCustom (Spoc.Kernel.relax_vector "^i^") "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) -> arg_string := i^" "^(!arg_string); arg_string2 := i^" "^(!arg_string2) | TyApp (l, t1, t2) -> begin match t2 with | TyId (_, id) -> (parseTyp t1 i ); | _ -> failwith "erf" end | _ -> failwith "apply_of_constraints Not TyId " 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 (_, id) when (String.compare (string_of_ident id) "int") = 0 -> incr idx; arg_string := "Spoc.Kernel.Int32 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when (String.compare (string_of_ident id) "int32") = 0 -> incr idx; arg_string := "Spoc.Kernel.Int32 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when (String.compare (string_of_ident id) "int64") = 0 -> incr idx; arg_string := "Spoc.Kernel.Int64 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when (String.compare (string_of_ident id) "float") = 0 -> incr idx; arg_string := "Spoc.Kernel.Float32 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when (String.compare (string_of_ident id) "float32") = 0 -> incr idx; arg_string := "Spoc.Kernel.Float32 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when (String.compare (string_of_ident id) "float64") = 0 -> incr idx; arg_string := "Spoc.Kernel.Float64 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vfloat32") = 0 -> incr idx; arg_string := "Spoc.Kernel.VFloat32 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vchar") = 0 -> incr idx; arg_string := "Spoc.Kernel.VChar "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_localvfloat32") = 0 -> incr idx; arg_string := "Spoc.Kernel.LocalFloat32 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vfloat64") = 0 -> incr idx; arg_string := "Spoc.Kernel.VFloat64 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vcomplex32") = 0 -> incr idx; arg_string := "Spoc.Kernel.VComplex32 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vint32") = 0 -> incr idx; arg_string := "Spoc.Kernel.VInt32 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vint64") = 0 -> incr idx; arg_string := "Spoc.Kernel.VInt64 "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vbool") = 0 -> incr idx; arg_string := "Spoc.Kernel.VCustom "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vcustom") = 0 -> incr idx; arg_string := "Spoc.Kernel.VCustom "^i^" "^(!arg_string); arg_string2 :=i^" "^(!arg_string2) | TyId (_, id) -> arg_string := i^" "^(!arg_string); arg_string2 := i^" "^(!arg_string2) | TyApp (l, t1, t2) -> begin match t2 with | TyId (_, id) -> (parseInvTyp t1 i ) | _ -> failwith "erf" end | _ -> failwith "apply_of_constraints Not 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") = 0 -> let _loc = l in (<:ctyp< ('spoc_c, 'spoc_d) Vector.vector>>) | TyId (l, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vchar") = 0 -> let _loc = l in (<:ctyp< ('spoc_e, 'spoc_f) Vector.vector>>) | TyId (l, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_localvfloat32") = 0 -> let _loc = l in (<:ctyp< ('spoc_g, 'spoc_h) Vector.vector>>) | TyId (l, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vfloat64") = 0 -> let _loc = l in (<:ctyp< ('spoc_i, 'spoc_j) Vector.vector>>) | TyId (l, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vcomplex32") = 0 -> let _loc = l in (<:ctyp< ('spoc_j, 'spoc_k) Vector.vector>>) | TyId (l, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vint32") = 0 -> let _loc = l in (<:ctyp< ('spoc_l, 'spoc_m) Vector.vector>>) | TyId (l, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vint64") = 0 -> let _loc = l in (<:ctyp< ('spoc_n, 'spoc_o) Vector.vector>>) | TyId (l, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vbool") = 0 -> let _loc = l in (<:ctyp< ('spoc_p,'spoc_q) Vector.vector>>) | TyId (l, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vcustom") = 0 -> let _loc = l in (<:ctyp< ('spoc_r,'spoc_s) Vector.vector>>) | TyId (_, id) -> t | TyApp (l, t1, t2) -> type_to_type t1 | _ -> failwith "apply_of_constraints Not TyId " 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") = 0 -> let _loc = l in (<:ctyp< (float, Bigarray.float32_elt) Vector.vector>>) | TyId (l, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vchar") = 0 -> let _loc = l in (<:ctyp< (char, Bigarray.int8_unsigned_elt) Vector.vector>>) | TyId (l, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_localvfloat32") = 0 -> let _loc = l in (<:ctyp< (float, Bigarray.float32_elt) Vector.vector>>) | TyId (l, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vfloat64") = 0 -> let _loc = l in (<:ctyp< (float, Bigarray.float64_elt) Vector.vector>>) | TyId (l, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vcomplex32") = 0 -> let _loc = l in (<:ctyp< (Complex.t, Bigarray.complex32_elt) Vector.vector>>) | TyId (l, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vint32") = 0 -> let _loc = l in (<:ctyp< (int32, Bigarray.int32_elt) Vector.vector>>) | TyId (l, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vint64") = 0 -> let _loc = l in (<:ctyp< (float, Bigarray.float64_elt) Vector.vector>>) | TyId (l, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vbool") = 0 -> let _loc = l in (<:ctyp< (bool, bool) Vector.vector>>) | TyId (l, id) when (String.compare (string_of_ident id) "acc_acc_Spoc_Vector_vcustom") = 0 -> let _loc = l in (<:ctyp< Vector.vector>>) | TyId (_, id) -> t | TyApp (_loc, t1, t2) -> <:ctyp< ($concrete_type_to_type t2$,$concrete_type_to_type t2$) $concrete_type_to_type t1$>> | _ -> failwith "apply_of_constraints Not TyId " 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, (PaId (loc, (ident_of_string loc (snd nv)) )), (type_to_type t) ) in let tuple = match l with [] -> assert false | [x] -> idx := !idx + 1; translate x | _ -> Ast.paCom_of_list (List.map (translate) l) in arg_string := ""; let array = let arr_content = let f t = arg_string := ""; parseTyp t (*(snd (List.nth !var_list !idx))*) (snd (List.nth !var_list (!idx))) ; expr_of_string loc (!arg_string^"; ") in idx := 0 ; let l = (List.map f l) in Ast.exSem_of_list (l) in ExArr(loc, arr_content) in idx := 1 ; (match l with [] -> assert false | [x] -> tuple | _ -> PaTup(loc, tuple)),array let first_vector = ref false let relaxed _loc nv = if not !first_vector then (first_vector := true; <:expr<$(ExId (_loc, (ident_of_string _loc (nv)) ))$>>) else <:expr<Spoc.Kernel.relax_vector $(ExId (_loc, (ident_of_string _loc (nv)) ))$>> 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) when ((string_of_ident id) = "acc_acc_Spoc_Vector_vint32") -> relaxed _loc nv | TyId (l, id) when ((string_of_ident id) = "acc_acc_Spoc_Vector_vint64") -> relaxed _loc nv | TyId (l, id) when ((string_of_ident id) = "acc_acc_Spoc_Vector_localvfloat32") -> relaxed _loc nv | TyId (l, id) when ((string_of_ident id) = "acc_acc_Spoc_Vector_vchar") -> relaxed _loc nv | TyId (l, id) when ((string_of_ident id) = "acc_acc_Spoc_Vector_vbool") -> relaxed _loc nv | TyId (l, id) when ((string_of_ident id) = "acc_acc_Spoc_Vector_vcustom") -> relaxed _loc nv | TyId (l, id) when ((string_of_ident id) = "acc_acc_Spoc_Vector_vcomplex32") -> relaxed _loc nv | TyApp (_loc, t1, t2) -> gen_inv_id t1 _loc nv | _ -> (ExId (_loc, (ident_of_string _loc (nv)) )) 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]; ExTyc (loc, gen_inv_id t loc (snd nv), (concrete_type_to_type t) ) in let tuple = match l with [] -> assert false | [x] -> translate x | _ -> Ast.exCom_of_list (List.map (translate) l) in arg_string := ""; let array = let arr_content = let f t = arg_string := ""; parseInvTyp t " " (*(snd (List.nth !var_list !idx))*) ; let arg = ((*print_endline ("arg: "^ !arg_string);*) String.sub !arg_string 12 ((String.length !arg_string - 15))) in (*Printf.printf "arg_string = %s\n" !arg_string; Printf.printf "arg_ = %s\n" (String.sub !arg_string 12 ((String.length !arg_string - 15))); *) PaApp (loc, PaId (loc, IdUid (_loc, arg)), PaId (loc, ident_of_string loc (snd (List.nth !var_list (!idx-1))))) in idx := 0 ; Ast.paSem_of_list (List.map f l) in PaArr(loc, arr_content) in idx := 1 ; (match l with | [] -> assert false | [x] -> tuple | _ -> ExTup(loc, tuple)),array 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.set $arr$ $c1$ $c2$ $newval$ >> | <:expr< Bigarray.Array3.get $arr$ $c1$ $c2$ $c3$ >> -> Some <:expr< Bigarray.Array3.set $arr$ $c1$ $c2$ $c3$ $newval$ >> | <:expr< Bigarray.Genarray.get $arr$ [| $coords$ |] >> -> Some <:expr< Bigarray.Genarray.set $arr$ [| $coords$ |] $newval$ >> | <:expr< Spoc.Mem.get $arr$ $c1$ >> -> Some <:expr< Spoc.Mem.set $arr$ $c1$ $newval$ >> | _ -> None DELETE_RULE Gram expr: SELF; "."; "("; SELF; ")" END DELETE_RULE Gram expr: SELF; "."; "["; SELF; "]" END DELETE_RULE Gram expr: SELF; "<-"; expr LEVEL "top" END EXTEND Gram GLOBAL: str_item sequence do_sequence expr ctyp opt_rec; (******************** external kernels **********************) expr: LEVEL "." [ LEFTA [ e0 = SELF; "."; "[<"; e1 = SELF; ">]" -> let e = expr_of_string _loc "Spoc.Mem.get" in <:expr< $e$ $e0$ $e1$ >> |e0 = SELF; "."; "("; e1 = SELF; ")" -> <:expr< $e0$ .( $e1$ ) >> |e0 = SELF; "."; "["; e1 = SELF; "]" -> <:expr< $e0$ .[ $e1$ ] >> ] ]; expr: LEVEL "." [ [ e1 = SELF; ":="; e2 = expr LEVEL "top" -> <:expr< $e1$ := $e2$ >> | e1 = SELF; "<-"; e2 = expr LEVEL "top" -> match bigarray_set _loc e1 e2 with Some e -> e | None -> ExAss (_loc, e1, e2) ] ]; str_item: [ [ "kernel"; lid = ident; ":"; typ = ctyp; "="; file_name = STRING; func_name = STRING -> let constraint_var, arg_list, id_list = parse_ctyp typ and id = IdLid (_loc, "kernel_"^(string_of_ident lid) )in let p1 = PaId (_loc, lid) in let k_typ = gen_ktyp _loc id_list in let inv_args = gen_inv_args _loc id_list in let args = gen_args _loc id_list in let k_fun = <:patt< $id:id$ >> in let exec_fun = <:binding< $k_fun$ = fun $fst args$ -> Spoc.Kernel.exec $snd args$ >> in let class_name = "class_kernel_"^(string_of_ident lid) and filename =ExStr (_loc, file_name) and funcname =ExStr (_loc, func_name) in let exec = ExId(_loc, id) in let gen_object = <:str_item< class ['a, 'b] $lid:class_name$ = object (self) inherit [$k_typ$, ('a,'b) Kernel.kernelArgs array ] Spoc.Kernel.spoc_kernel $filename$ $funcname$ method exec = $exec$ method args_to_list = fun $fst args$ -> $snd args$ method list_to_args = function | $snd inv_args$ -> $fst inv_args$ | _ -> failwith "spoc_kernel_extension error" end let $p1$ = new $lid:class_name$;; >> in arg_string := ""; StSem(_loc, <:str_item< open Spoc.Kernel >>, StSem(_loc, StVal (_loc, ReNil,exec_fun), gen_object)) ]]; END
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>