Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use functions in the limited API #5871

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ option(SINGLEGPU "Disable all mnmg components and comms libraries" OFF)
set(CUML_RAFT_CLONE_ON_PIN OFF)



# todo: use CMAKE_MESSAGE_CONTEXT for prefix for logging.
# https://github.com/rapidsai/cuml/issues/4843
message(VERBOSE "CUML_PY: Build only cuML CPU Python components.: ${CUML_CPU}")
Expand Down
21 changes: 13 additions & 8 deletions python/cuml/ensemble/randomforest_shared.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2020-2023, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,9 @@

# distutils: language = c++

from cpython.buffer cimport PyObject_GetBuffer, PyBuffer_Release, PyBUF_FULL_RO

from libcpp.vector cimport vector
from cpython.object cimport PyObject
from libc.stdint cimport uintptr_t
from libcpp.memory cimport unique_ptr
from typing import Dict, List, Union
Expand All @@ -37,9 +38,6 @@ cdef extern from "treelite/tree.h" namespace "treelite":
@staticmethod
unique_ptr[Model] DeserializeFromPyBuffer(const vector[TreelitePyBufferFrame] &) except +

cdef extern from "Python.h":
Py_buffer* PyMemoryView_GET_BUFFER(PyObject* mview)

cdef class PyBufferFrameWrapper:
cdef TreelitePyBufferFrame _handle
cdef Py_ssize_t shape[1]
Expand Down Expand Up @@ -92,18 +90,25 @@ def get_frames(model: uintptr_t) -> List[memoryview]:
def init_from_frames(frames: List[np.ndarray],
format_str: List[str], itemsize: List[int]) -> uintptr_t:
cdef vector[TreelitePyBufferFrame] cpp_frames
# Need to keep track of the buffers to release them later.
cdef vector[Py_buffer] buffers
cdef Py_buffer* buf
cdef TreelitePyBufferFrame cpp_frame
format_bytes = [s.encode('utf-8') for s in format_str]
for i, frame in enumerate(frames):
x = memoryview(frame)
buf = PyMemoryView_GET_BUFFER(<PyObject*>x)
buffers.emplace_back()
buf = &buffers.back()
PyObject_GetBuffer(frame, buf, PyBUF_FULL_RO)
cpp_frame.buf = buf.buf
cpp_frame.format = format_bytes[i]
cpp_frame.itemsize = itemsize[i]
cpp_frame.nitem = buf.len // itemsize[i]
cpp_frames.push_back(cpp_frame)
return <uintptr_t> _init_from_frames(cpp_frames)
output = <uintptr_t> _init_from_frames(cpp_frames)
cdef int j
for j in range(buffers.size()):
PyBuffer_Release(&buffers[j])
return output


def treelite_serialize(
Expand Down
Loading