MCPcopy Create free account
hub / github.com/NVIDIA/DALI / ExposeBufferPolicyFunctions

Function ExposeBufferPolicyFunctions

dali/python/backend_impl.cc:2202–2295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2200#endif // DALI_BUILD_PROTO3
2201
2202void ExposeBufferPolicyFunctions(py::module &m) {
2203 m.def("SetHostBufferShrinkThreshold", [](double ratio) {
2204 if (ratio < 0 || ratio > 1)
2205 throw py::value_error("Shrink threshold must be between 0 (never shrink) "
2206 "and 1 (always shrink).");
2207
2208 Buffer<CPUBackend>::SetShrinkThreshold(ratio);
2209 });
2210
2211 m.def("SetHostBufferGrowthFactor", [](double factor) {
2212 const double max_factor = std::min(
2213 Buffer<CPUBackend>::kMaxGrowthFactor,
2214 Buffer<GPUBackend>::kMaxGrowthFactor);
2215
2216 if (factor < 1 || factor > max_factor)
2217 throw py::value_error(make_string("Growth factor must be between 1 and ", max_factor, "."));
2218
2219 Buffer<CPUBackend>::SetGrowthFactor(factor);
2220 });
2221
2222 m.def("SetDeviceBufferGrowthFactor", [](double factor) {
2223 const double max_factor = Buffer<CPUBackend>::kMaxGrowthFactor;
2224 if (factor < 1 || factor > max_factor)
2225 throw py::value_error(make_string("Growth factor must be between 1 and ", max_factor, "."));
2226
2227 Buffer<GPUBackend>::SetGrowthFactor(factor);
2228 });
2229
2230 m.def("SetBufferGrowthFactor", [](double factor) {
2231 const double max_factor = Buffer<GPUBackend>::kMaxGrowthFactor;
2232 if (factor < 1 || factor > max_factor)
2233 throw py::value_error(make_string("Growth factor must be between 1 and ", max_factor, "."));
2234
2235 Buffer<CPUBackend>::SetGrowthFactor(factor);
2236 Buffer<GPUBackend>::SetGrowthFactor(factor);
2237 });
2238
2239 m.def("GetHostBufferShrinkThreshold", Buffer<CPUBackend>::GetShrinkThreshold);
2240 m.def("GetHostBufferGrowthFactor", Buffer<CPUBackend>::GetGrowthFactor);
2241 m.def("GetDeviceBufferGrowthFactor", Buffer<GPUBackend>::GetGrowthFactor);
2242 m.def("RestrictPinnedMemUsage", RestrictPinnedMemUsage);
2243 m.def("GetCUDADeviceCount", []() {
2244 int count = 0;
2245 auto err = cudaGetDeviceCount(&count);
2246 if (err == cudaErrorNoDevice || err == cudaErrorInsufficientDriver)
2247 return 0;
2248 CUDA_CALL(err);
2249 return count;
2250 });
2251 m.def("SetCUDACurrentDevice", [](int device_id) {
2252 CUDA_CALL(cudaSetDevice(device_id));
2253 });
2254 m.def("GetCUDACurrentDevice", []() {
2255 int device_id = 0;
2256 CUDA_CALL(cudaGetDevice(&device_id));
2257 return device_id;
2258 });
2259 m.def("GetCUDAStreamDevice", [](py::object stream) {

Callers 1

PYBIND11_MODULEFunction · 0.85

Calls 8

SetShrinkThresholdFunction · 0.85
SetGrowthFactorFunction · 0.85
CUDA_CALLFunction · 0.85
DeviceFromStreamFunction · 0.85
minFunction · 0.50
make_stringFunction · 0.50
streamMethod · 0.45

Tested by

no test coverage detected