Code Monkey home page Code Monkey logo

cupy-nanobind-example's Introduction

cupy-nanobind-example

A minimal demo of a Python project that uses scikit-build-core to compile a CUDA CPython extension that accepts a cupy array via nanobind's DLPack support. This is possibly the most technologies I've strung together in a single sentence.

Build and install (basic)

$ pip install .

Build and install (editable)

$ pip install scikit-build-core nanobind ninja
$ pip install -e . --no-build-isolation

Test

$ python test.py

cupy-nanobind-example's People

Contributors

lgarrison avatar

Stargazers

 avatar  avatar

Watchers

 avatar

cupy-nanobind-example's Issues

How to map to host function in separate file?

I've been playing around with it this morning and it is very convenient, thanks a lot!

Can you give me a hand with how to map my function sitting in a separate file?

Problem

Inside a pointing.cpp I map to the function,

    m.def("CUpointing_cparr",
        &CUpointing_cparr<double>,
        "thetas"_a.noconvert(),
        "phi0"_a.noconvert(),
        "nphis"_a.noconvert(),
        "ringstarts"_a.noconvert(),
        "synthmap"_a.noconvert(),
        "outarr_pt"_a.noconvert(),
        "outarr_pp"_a.noconvert()
    );

where CUpointing_cparr is in pointing.cu

Inside pointing.cpp is #include "pointing.cuh", with "pointing.cuh" having the CUpointing_cparr definition.

Compiler compiles, but importing in Python gives the error,

import pysht_interface.popy as popy
ImportError: /mnt/home/sbelkner/venv/pysht/lib/python3.10/site-packages/pysht_interface/popy.cpython-310-x86_64-linux-gnu.so:
undefined symbol: 
_Z15Cpointing_cparrIdEvN8nanobind7ndarrayIJKT_NS0_5shapeIJLm18446744073709551615EEEENS0_6device4cudaEEEES8_NS1_IJKiS5_S7_EEESA_S8_NS1_IJS2_S5_S7_EEESB_

which tells me that it's ignoring the header file, and cannot find the function?

The CMakeLists.txt contains

nanobind_add_module(popy
  pointing.cu
  pointing.h
  pointing.cpp
  pointing.cuh
)

Note: everything works when CUpointing_cparr() is in the same file as the m.def()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.