{"id":15691037,"url":"https://github.com/pityka/aten-scala","last_synced_at":"2025-05-08T00:50:23.640Z","repository":{"id":57734485,"uuid":"266578937","full_name":"pityka/aten-scala","owner":"pityka","description":"jni bindings to aten from libtorch","archived":false,"fork":false,"pushed_at":"2025-04-20T15:32:57.000Z","size":9173,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-20T16:32:58.611Z","etag":null,"topics":["libtorch","scala"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pityka.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-24T16:19:58.000Z","updated_at":"2025-04-20T15:33:14.000Z","dependencies_parsed_at":"2025-03-11T15:52:21.307Z","dependency_job_id":null,"html_url":"https://github.com/pityka/aten-scala","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pityka%2Faten-scala","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pityka%2Faten-scala/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pityka%2Faten-scala/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pityka%2Faten-scala/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pityka","download_url":"https://codeload.github.com/pityka/aten-scala/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252978686,"owners_count":21834913,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["libtorch","scala"],"created_at":"2024-10-03T18:19:18.891Z","updated_at":"2025-05-08T00:50:23.623Z","avatar_url":"https://github.com/pityka.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![maven](https://img.shields.io/maven-central/v/io.github.pityka/aten-scala-core_2.13.svg)](https://repo1.maven.org/maven2/io/github/pityka/aten-scala-core_2.13/)\n\n# Build documentation \n\nThe JNI bindings are built with clang++ for Mac (arm64) and for Linux (x86). \nThe build runs on a Mac and uses Docker for cross compilation. \nThe docker image used for building (and possible at runtime) is defined in `docker-runtime/Dockerfile`. This image is pushed to the Docker Hub (https://hub.docker.com/r/pityka/base-ubuntu-libtorch/tags?page=1\u0026ordering=last_updated), and by default the build will pull it. \n\n## Prerequisites\n- needs a macs with clang++ installed and set up for cross compiling.\n- needs docker on the mac \n- on the mac needs the libtorch shared libraries in /usr/local/lib/. Read on.\n- needs bloop (https://scalacenter.github.io/bloop/) and sbt (https://www.scala-sbt.org/).\n\n\n## Build\n1. `make prepare` - this creates bloop build definitions from sbt the sbt build definition\n2. Copy from one to the other \n3. `make test`\n4. `make test-linux` - builds for linux and runs tests in a linux container (needs docker for mac, will pull `pityka/base-ubuntu-libtorch` from docker hub)\n5. `make test-cuda` - runs tests in a cuda enabled remote docker context\n\n\n## Publishing\n- `make publishLocal` - publishes artifacts locally\n- `make publish` - publishes artifacts to github packages. \n- `bash publish.sh` - publishes the artifacts to Maven Central\n\n# How this works\nThe Makefile will generate Java and C++ sources and create a JNI native library.\n\n`parser/` holds a parser for `parseable.h` which is a subset of the `libtorch/include/ATen/Functions.h`. This parser generates cpp (`./wrapper.cpp`) and java JNI code (`./aten-scala/core/src/main/java/ATen.java`). The cpp code is compiled to `./aten-scala/jni-osx/src/main/resources/libatenscalajni.dylib`.\n\n`aten-scala/` holds an sbt project with two subprojects. `aten-scala/core` is the Java counterpart of the binding. It depends on Scala because `std::tuple` is translated into Scala tuples.  `aten-scala/jni-osx` contains no source code but its Maven artifact contains the native library.\n\n# Libtorch runtime dependency\nLibtorch is linked dynamically during runtime. \n## OSX\nOn OSX the jni shared library always looks for libtorch in `/usr/local/lib/`.\nYou can get the libtorch libraries with `pip3 install torch` then copy the necessary files to /usr/local/lib/. E.g. cp `/usr/local/lib/python3.9/site-packages/torch/lib/* /usr/local/lib/`. \nHowever one needs to copy `/usr/local/lib/python3.9/site-packages/torch/.dylibs/libomp.dylib` as well to `/usr/local/.dylibs/` (depends on the libtorch version).\n## Linux\nOn Linux there is no @rpath baked in the jni shared library. \nUse LD_LIBRARY_PATH to make sure the linker finds libtorch.\nSee the `docker-runtime/Dockerfile`s on how to do this.\n\n# Docker image for Linux with libtorch and CUDA\nSee `docker-runtime/Dockerfile`. This image is pushed to the Docker Hub (https://hub.docker.com/r/pityka/base-ubuntu-libtorch/tags?page=1\u0026ordering=last_updated).\n\nThe image also has Java 8 and sbt. It is ready to make use of this library on Linux.\n\n# License\nSee LICENSE file.\n\n# Notes\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpityka%2Faten-scala","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpityka%2Faten-scala","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpityka%2Faten-scala/lists"}