Skip to content

Commit

Permalink
Merge pull request #25 from kornia/release-aarch64
Browse files Browse the repository at this point in the history
Add support for aarch64 via docker
  • Loading branch information
edgarriba committed Jan 7, 2023
2 parents 8117411 + 96266d2 commit 8d6336b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/release.yml
Expand Up @@ -13,9 +13,13 @@ jobs:
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
target: [x86_64]
target: [x86_64, aarch64]
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to the Container registry
uses: docker/login-action@v1
with:
Expand All @@ -24,7 +28,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- uses: messense/maturin-action@v1
with:
container: ghcr.io/kornia/kornia-rs/release:latest
container: ghcr.io/kornia/kornia-rs/release-${{ matrix.target }}:latest
target: ${{ matrix.target }}
manylinux: auto
args: --release --out dist -i python${{ matrix.python-version }}
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/release_docker.yml
Expand Up @@ -10,10 +10,17 @@ env:
jobs:
build_docker:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- arch: amd64
label: x86_64
- arch: arm64
label: aarch64
steps:
-
name: Checkout the repository
uses: actions/checkout@v2
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand All @@ -32,7 +39,7 @@ jobs:
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/release.Dockerfile
platforms: linux/amd64
file: ./docker/release-${{ matrix.arch }}.Dockerfile
platforms: linux/${{ matrix.arch }}
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/release:latest
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/release-${{ matrix.label }}:latest
File renamed without changes.
12 changes: 12 additions & 0 deletions docker/release-arm64.Dockerfile
@@ -0,0 +1,12 @@
FROM ghcr.io/rust-cross/manylinux2014-cross:aarch64

# rust image comes with sh, we like bash more
SHELL ["/bin/bash", "-c"]

RUN uname -a

RUN apt-get update --fix-missing && \
apt-get install -y --no-install-recommends \
gcc-aarch64-linux-gnu \
&& \
apt-get clean
7 changes: 4 additions & 3 deletions src/dlpack_py.rs
Expand Up @@ -3,12 +3,13 @@ use dlpack_rs as dlpack;

use pyo3::prelude::*;
use std::ffi::{c_void, CStr, CString};
use std::os::raw::c_char;

const DLPACK_CAPSULE_NAME: &[u8] = b"dltensor\0";

// desctructor function for the python capsule
unsafe extern "C" fn dlpack_capsule_destructor(capsule: *mut pyo3::ffi::PyObject) {
if pyo3::ffi::PyCapsule_IsValid(capsule, DLPACK_CAPSULE_NAME.as_ptr() as *const i8) == 1 {
if pyo3::ffi::PyCapsule_IsValid(capsule, DLPACK_CAPSULE_NAME.as_ptr() as *const c_char) == 1 {
// println!("Is an invalid capsule!");
return;
}
Expand All @@ -17,7 +18,7 @@ unsafe extern "C" fn dlpack_capsule_destructor(capsule: *mut pyo3::ffi::PyObject

let expected_name = CString::new("dltensor").unwrap();

let current_name_ptr: *const i8 = pyo3::ffi::PyCapsule_GetName(capsule);
let current_name_ptr: *const c_char = pyo3::ffi::PyCapsule_GetName(capsule);
let current_name = CStr::from_ptr(current_name_ptr);
// println!("Expected Name: {:?}", expected_name);
// println!("Current Name: {:?}", current_name);
Expand Down Expand Up @@ -94,7 +95,7 @@ pub fn cvtensor_to_dlpack(x: &cv::Tensor, py: Python) -> PyResult<PyObject> {
let capsule: PyObject = unsafe {
let ptr = pyo3::ffi::PyCapsule_New(
&*dlm_tensor_bx as *const dlpack::DLManagedTensor as *mut c_void,
DLPACK_CAPSULE_NAME.as_ptr() as *const i8,
DLPACK_CAPSULE_NAME.as_ptr() as *const c_char,
Some(dlpack_capsule_destructor as pyo3::ffi::PyCapsule_Destructor),
);
PyObject::from_owned_ptr(py, ptr)
Expand Down

0 comments on commit 8d6336b

Please sign in to comment.