Comments (15)
Thank you @kmaehashi @leofang . Currently, I am using the pointer in RawKernel.kernel.ptr
just as @leofang pointed out. However, I also agree the suggestion of @kmaehashi is right.
The motivation for my question is to use cupy
as a compiler to compile custom CUDA extensions on JAX. JAX's jit system needs to register an XLA custom call when using customized Cuda kernels. Usually, we need to write Cuda code, pre-compile it, bind it to Python, and register kernels in XLA. To remove such a complex process, we can directly compile the source code (as a Python code) at the Python level, then get the compiled kernel, throw it into the custom call, and all things are compatible with jax's jit system, with the minimal efforts (only writing the Python string).
Currently, we are working on this functionality.
from cupy.
Are there any specific reasons to use CuPy for that purpose? If your C++ application needs to compile CUDA code on the fly, you can just call NVRTC to get cubin/ptx.
from cupy.
You cannot launch a kernel defined by cupy.RawKernel
, however, an option may be using cupy.RawModule
that can be used to load a .cubin
or .ptx
file. Does it fit?
https://docs.cupy.dev/en/stable/reference/generated/cupy.RawModule.html
from cupy.
So a great answer! Therefore, the key is to use RawModule
to generate a .cubin
or .ptx
file, then I load the generated under the c++ backend to run. Am I right?
from cupy.
Moreover, can cupyx.jit.rawkernel
compiled kernels to be saved into a .ptx
file?
from cupy.
What I meant was the opposite. You write in C++ (.cu file) and compile it into .cubin or .ptx files, then you can use them from the RawModule. cupyx.jit.rawkernel
doesn't have a feature to save .ptx
file in a way that is easily usable from external programs.
from cupy.
Thanks for the explanation. I am wondering how to get the compiled binary when using cupy.RawKernel?
from cupy.
Please supply a path to the compiled binary to path
argument of RawModule
(not RawKernel
). https://docs.cupy.dev/en/stable/reference/generated/cupy.RawModule.html
from cupy.
I try to use cupy
to compile the cuda code, and get its compiled kernel, rather than providing the path of a compiled CUDA binary (*.cubin) or a PTX file. So, I am wondering how to provide the cuda source code and then get the cupy compiled binary file path?
from cupy.
Or, how can I get the kernel under $HOME/.cupy/kernel_cache/
directory? The name of a .cubin
file seems have no pattern?
from cupy.
In theory, for a given RawKernel
(either you use it directly, or get it via RawModule.get_function
) you can retrieve the CUFunction
pointer via RawKernel.kernel.ptr
, but
- This is not public API
- This is untested
It's unclear to me either why you'd need this, @chaoming0625 could you elaborate?
from cupy.
Moreover, can I get the pointer
of the function after compiling through cupyx.jit.rawkernel
?
from cupy.
Thanks for sharing your use case @chaoming0625, this is very interesting!
Would you be able to point us how you use this capability to make CuPy and Jax interoperable at the kernel level? I would love to see how it allows you to avoid writing complex boilerplate code. Eventually, I would like to learn how to craft a small interop demo like the one we showed for PyTorch-CuPy:
https://docs.cupy.dev/en/stable/user_guide/interoperability.html#using-custom-kernels-in-pytorch
If you already have a small demo that we can copy/paste to the document that's even better! 😄
Moreover, can I get the
pointer
of the function after compiling throughcupyx.jit.rawkernel
?
Right now it's not public API either, but according to the internal implementation (subject to change)
Line 91 in 4179286
it is possible to get the
Function
object from jit.rawkernel._cache
once instantiated (it's the CUFunction
pointer via Function.ptr
as before.
If you show us your workflow as I ask above, it'll help us stabilize the interface and expose these features properly. Thanks!
from cupy.
Related Issues (20)
- Pre-populate and ship a Jitify cache? HOT 4
- Support Cuda Stream creation with Priority HOT 3
- [Deleted]
- Typecasting issue HOT 2
- Support cuDNN 9.0 HOT 4
- Jitify cache paths on Windows in Cupy13 HOT 3
- Revisit: Using upstream Thrust complex headers and drop the vendored ones HOT 1
- Failed to import CuPy
- Failed to import CuPy. HOT 2
- How does CuPy work? HOT 1
- Cannot install CuPy from source on ROCm 6.0.2 HOT 1
- `ndimage.shift` results in incorrect values for inplace for float arrays HOT 2
- Possibly mistaken usage of the `cupyx.jit.thrust.device` execution policy in the JIT context? HOT 3
- Issue with cupy.random.XORWOW when generating random numbers beyond 2.1 billion HOT 2
- `rfftn`/`fftn` shape mismatch with NumPy when `s` is specified?
- Error when calling shares_memory HOT 11
- AttributeError: module 'numpy' has no attribute 'bool'. HOT 3
- ARM64 build incomplete for version 12.3 - missing NCCL library HOT 5
- `test_sos_freqz_against_mp` test trying to import nonexisting local `mpsig` module HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cupy.