-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working through system to define library symbols
- Loading branch information
Showing
7 changed files
with
304 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ pom.xml.asc | |
graalvm* | ||
tech.v3.datatype.main | ||
resources | ||
jdk-16 | ||
jdk-16 | ||
library_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
(ns tech.v3.datatype.expose-fn | ||
(:require [tech.v3.datatype :as dtype] | ||
[tech.v3.datatype.native-buffer :as native-buffer]) | ||
(:import [tech.v3.datatype.ffi Pointer])) | ||
|
||
|
||
(defn add-two-nums | ||
[num-a num-b] | ||
(+ num-a num-b)) | ||
|
||
|
||
(defn allocate-buffer | ||
[len] | ||
;;setup buffer to be manually freed. | ||
(when-not (== 0 len) | ||
(dtype/make-container :native-heap :int8 {:resource-type nil} len))) | ||
|
||
|
||
(defn set-buffer | ||
[buffer len val] | ||
(-> (native-buffer/wrap-address (.address ^Pointer buffer) len nil) | ||
(dtype/set-constant! val))) | ||
|
||
|
||
(defn free-buffer | ||
[buffer] | ||
(when (and buffer (not= 0 (.address ^Pointer buffer))) | ||
(native-buffer/free (native-buffer/wrap-address buffer 1 nil)))) | ||
|
||
|
||
|
||
(comment | ||
(do | ||
(require '[tech.v3.datatype.ffi.graalvm :as graalvm]) | ||
(def cls-def | ||
(with-bindings {#'*compile-path* "library_test/classes"} | ||
(graalvm/expose-clojure-functions | ||
{#'add-two-nums {:rettype :int64 | ||
:argtypes [['lhs :int64] | ||
['rhs :int64]]} | ||
#'allocate-buffer {:rettype :pointer? | ||
:argtypes [['len :int64]]} | ||
#'set-buffer {:rettype :void | ||
:argtypes [['buffer :pointer] | ||
['len :int64] | ||
['val :int8]]} | ||
#'free-buffer {:rettype :void | ||
:argtypes [['buffer :pointer?]]} | ||
|
||
} | ||
'libdtype.ExposeFnTest | ||
{:instantiate? true}))) | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
lein clean | ||
lein uberjar | ||
|
||
pushd library_test | ||
|
||
$GRAALVM_HOME/bin/native-image \ | ||
--report-unsupported-elements-at-runtime \ | ||
--initialize-at-build-time \ | ||
--no-fallback \ | ||
--no-server \ | ||
-H:+ReportExceptionStackTraces \ | ||
-J-Dclojure.spec.skip-macros=true \ | ||
-J-Dclojure.compiler.direct-linking=true \ | ||
-J-Dtech.v3.datatype.graal-native=true \ | ||
-jar ../target/dtype-next.jar \ | ||
-cp classes \ | ||
-H:Name=libdtype \ | ||
--shared | ||
|
||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
#!/bin/bash | ||
|
||
wget https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-20.2.0/graalvm-ce-java8-linux-amd64-20.2.0.tar.gz | ||
tar -xvzf graalvm-ce-java8-linux-amd64-20.2.0.tar.gz | ||
ln -s "$(pwd)/graalvm-ce-java8-20.2.0" "$(pwd)/graalvm" | ||
rm graalvm-ce-java8-linux-amd64-20.2.0.tar.gz | ||
|
||
GRAAL_VERSION="21.0.0.2" | ||
|
||
wget https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-$GRAAL_VERSION/graalvm-ce-java8-linux-amd64-$GRAAL_VERSION.tar.gz | ||
tar -xvzf graalvm-ce-java8-linux-amd64-$GRAAL_VERSION.tar.gz | ||
ln -s "$(pwd)/graalvm-ce-java8-$GRAAL_VERSION" "$(pwd)/graalvm" | ||
rm graalvm-ce-java8-linux-amd64-$GRAAL_VERSION.tar.gz | ||
graalvm/bin/gu install native-image |
Oops, something went wrong.