rmm
rmm copied to clipboard
[FEA] Python bindings for `rmm::mr::pinned_host_memory_resource`
Is your feature request related to a problem? Please describe.
Add Python bindings for pinned_host_memory_resource
added in #1392 .
Hi, I would like to work on this issue. But I don't fully understand how to solve this. I am going through the cython documentation. I have also located the files I need to change - https://github.com/rapidsai/rmm/blob/branch-24.02/python/rmm/_lib/memory_resource.pyx
Would you mind sharing the steps to take to do so? Here is my (maybe incorrect) understanding so far -
- Create a class definition like https://github.com/rapidsai/rmm/blob/branch-24.02/python/rmm/_lib/memory_resource.pyx#L126
- Create python class PinnedHostMemoryResource and define the functions inside
- Add entry to python/rmm/mr.py
- Add tests to python/rmm/tests/test_rmm.py
@willtryagain that sounds about right! Thanks and we look forward to your contribution. Please make sure you also look at the RAPIDS contributing docs. Also this page is useful for dates; we are just starting 24.04 so make sure you target branch-24.04
with your PR.
Hey @harrism ,
Can you direct me on how to debug this error please?
I got this when I ran
cmake .. -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX.
I was busy with other deadlines so sorry for the late response.
Hey @harrism ,
Can you direct me on how to debug this error please?
I got this when I ran
cmake .. -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX.
I was busy with other deadlines so sorry for the late response.
Something looks very strange with your environment from that error message. What did you do to set up the development environment for RMM?
Hello @wence- ,
I have followed the README instructions
- git clone the latest version
- create conda env using
conda env create --name rmm_dev --file conda/environments/all_cuda-122_arch-x86_64.yaml
. I have nvcc 12.3 so this may be a problem. - follow build instructions
$ mkdir build # make a build directory $ cd build # enter the build directory $ cmake .. -DCMAKE_INSTALL_PREFIX=/install/path # configure cmake ... use $CONDA_PREFIX if you're using Anaconda
Thanks.
OK, thanks. I have a CTK 12.3 install here, so maybe I can reproduce.
Hmm, I could not reproduce, I did (I used mamba not conda, but everything else is the same). On ce3af2c46b8b:
git clean -fdx # there's no magic behind the curtain
mamba env create --name rmm-dev --file conda/environments/all_cuda-122_arch-x86_64.yaml
mamba activate rmm-dev
mkdir build-test
cd build-test
cmake .. -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX
make -j
Without any issues.
Can you show the output (in the activated rmm_dev
environment) of conda list
?
An alternative to trying to get the development environment set up manually is (easiest if you use vscode, but possible without) to use the devcontainer setup we have in the repository (needs some setup in advance setting up the nvidia container toolkit locally, https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).
Hey @wence- ,
Thanks. I also wanted to inform that while running cmake it failed CMAKE_HAVE_LIBC_PTHREAD.
Here is the conda list output.
Hmm, that is identical to mine, so I am somewhat at a loss as to what broke
Highly recommend using dev containers to avoid problems.
Hi guys, I was able to build the library after switching to a different OS. It passed all the tests. Can you tell what methods to include in the PinnedHostMemoryResource class? I am guessing allocate and deallocate.
Also, for including the cpp class is this correct
cdef extern from "rmm/mr/pinned_host_memory_resource.hpp" \
namespace "rmm::mr" nogil:
cdef cppclass pinned_host_memory_resource:
pinned_host_memory_resource() except +
Thanks
This is probably a bit harder than I originally thought, because pinned_host_memory_resource is not a device_memory_resource
. It's the first example of an MR that implements the cuda::mr::memory_resource
concept. Therefore there will need to be new Cython bindings added.
On further thought perhaps this is not a good first issue, so I'm removing that label. Still up to you if you want to try @willtryagain, but for me to explain it I might have to figure out how to write the code. :)
Ok @harrism Can you give me pointers to resources that can help me understand what to do? I am comfortable in C++ and Python but not much familiar with cython bindings. I would study more about cython.
As with the extern cdef cppclass
classes in memory_resource.pyx
, I think you would need an extern cppclass for host_pinned_memory_resource
, and then a cdef class HostPinnedMemoryResource
that calls its functions. The analogy would be device_memory_resource
and DeviceMemoryResource
.
But there is a problem. Unlike all the other MRs in RMM Python, HostPinnedMemoryResource is not a DeviceMemoryResource. So we need to rethink our inheritance.