1 /* Used to collect profiles of old versions of PyTorch. */ 2 #include <callgrind.h> 3 #include <pybind11/pybind11.h> 4 _valgrind_supported_platform()5bool _valgrind_supported_platform() { 6 #if defined(NVALGRIND) 7 return false; 8 #else 9 return true; 10 #endif 11 } 12 _valgrind_toggle()13void _valgrind_toggle() { 14 #if defined(NVALGRIND) 15 TORCH_CHECK(false, "Valgrind is not supported."); 16 #else 17 CALLGRIND_TOGGLE_COLLECT; 18 #endif 19 } 20 _valgrind_toggle_and_dump_stats()21void _valgrind_toggle_and_dump_stats() { 22 #if defined(NVALGRIND) 23 TORCH_CHECK(false, "Valgrind is not supported."); 24 #else 25 // NB: See note in Module.cpp 26 CALLGRIND_TOGGLE_COLLECT; 27 CALLGRIND_DUMP_STATS; 28 #endif 29 } 30 PYBIND11_MODULE(callgrind_bindings,m)31PYBIND11_MODULE(callgrind_bindings, m) { 32 m.def("_valgrind_supported_platform", &_valgrind_supported_platform); 33 m.def("_valgrind_toggle", &_valgrind_toggle); 34 m.def("_valgrind_toggle_and_dump_stats", &_valgrind_dump_stats); 35 } 36