Skip to content

Commit

Permalink
Fix fatal errors for cache object
Browse files Browse the repository at this point in the history
GIL is not acquired when using Python object.

Signed-off-by: Gigon Bae <[email protected]>
  • Loading branch information
gigony committed Oct 27, 2023
1 parent 5d91f19 commit 5f78da9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions python/pybind11/cache/cache_py.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, NVIDIA CORPORATION.
* Copyright (c) 2021-2023, 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 Down Expand Up @@ -53,22 +53,21 @@ void init_cache(py::module& cache)
py::call_guard<py::gil_scoped_release>())
.def_property("free_memory", &ImageCache::free_memory, nullptr, doc::ImageCache::doc_free_memory,
py::call_guard<py::gil_scoped_release>())
.def("record", &py_record, doc::ImageCache::doc_record, py::call_guard<py::gil_scoped_release>(), //
.def("record", &py_record, doc::ImageCache::doc_record, //
py::arg("value") = py::none())
.def_property("hit_count", &ImageCache::hit_count, nullptr, doc::ImageCache::doc_hit_count,
py::call_guard<py::gil_scoped_release>())
.def_property("miss_count", &ImageCache::miss_count, nullptr, doc::ImageCache::doc_miss_count,
py::call_guard<py::gil_scoped_release>())
.def("reserve", &py_image_cache_reserve, doc::ImageCache::doc_reserve, py::call_guard<py::gil_scoped_release>(), //
.def("reserve", &py_image_cache_reserve, doc::ImageCache::doc_reserve, //
py::arg("memory_capacity"));

cache.def("preferred_memory_capacity", &py_preferred_memory_capacity, doc::doc_preferred_memory_capacity, //
py::arg("img") = py::none(), //
py::arg("image_size") = std::nullopt, //
py::arg("tile_size") = std::nullopt, //
py::arg("patch_size") = std::nullopt, //
py::arg("bytes_per_pixel") = 3, //
py::call_guard<py::gil_scoped_release>());
py::arg("bytes_per_pixel") = 3);
}

bool py_record(ImageCache& cache, py::object value)
Expand Down
4 changes: 2 additions & 2 deletions python/pybind11/cucim_py.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
* Copyright (c) 2020-2023, 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 Down Expand Up @@ -107,7 +107,7 @@ PYBIND11_MODULE(_cucim, m)
py::class_<CuImage, std::shared_ptr<CuImage>>(m, "CuImage", py::dynamic_attr()) //
.def(py::init<const std::string&>(), doc::CuImage::doc_CuImage, py::call_guard<py::gil_scoped_release>(), //
py::arg("path")) //
.def_static("cache", &py_cache, doc::CuImage::doc_cache, py::call_guard<py::gil_scoped_release>(), //
.def_static("cache", &py_cache, doc::CuImage::doc_cache, //
py::arg("type") = py::none()) //
.def_static("profiler", &py_profiler, doc::CuImage::doc_profiler, py::call_guard<py::gil_scoped_release>()) //
.def_property_readonly_static("is_trace_enabled", &py_is_trace_enabled, doc::CuImage::doc_is_trace_enabled,
Expand Down

0 comments on commit 5f78da9

Please sign in to comment.