未验证 提交 770501b8 编写于 作者: L Leo Chen 提交者: GitHub

add thread name for dataloader (#46990)

上级 f856fc8d
......@@ -27,6 +27,7 @@ limitations under the License. */
#else
#include <unistd.h>
#endif
#include "glog/logging.h"
#include "paddle/fluid/framework/new_executor/workqueue/thread_data_registry.h"
#include "paddle/fluid/platform/macros.h" // import DISABLE_COPY_AND_ASSIGN
......@@ -115,6 +116,7 @@ bool SetCurrentThreadName(const std::string& name) {
return false;
}
instance.SetCurrentThreadData(name);
VLOG(4) << __func__ << " " << name;
return true;
}
......
......@@ -57,7 +57,7 @@ ThreadId GetCurrentThreadId();
// create/destory when using it.
std::unordered_map<uint64_t, ThreadId> GetAllThreadIds();
static constexpr const char* kDefaultThreadName = "unset";
static constexpr const char* kDefaultThreadName = "unnamed";
// Returns kDefaultThreadName if SetCurrentThreadName is never called.
std::string GetCurrentThreadName();
......
......@@ -854,6 +854,8 @@ PYBIND11_MODULE(libpaddle, m) {
m.def("_set_paddle_lib_path", &paddle::platform::dynload::SetPaddleLibPath);
m.def("set_current_thread_name", &paddle::platform::SetCurrentThreadName);
m.def("_promote_types_if_complex_exists",
&paddle::framework::PromoteTypesIfComplexExists);
......
......@@ -205,6 +205,7 @@ class _DataLoaderIterSingleProcess(_DataLoaderIterBase):
# If we do not set cudaDeviceId in new thread, the default cudaDeviceId will be 0,
# Which may cost hundreds of MB of GPU memory on CUDAPlace(0) if calling some cuda
# APIs in this thread.
core.set_current_thread_name("Dataloader_" + str(id(self)))
_set_expected_place(legacy_expected_place)
while not self._thread_done_event.is_set():
......@@ -530,6 +531,7 @@ class _DataLoaderIterMultiProcess(_DataLoaderIterBase):
# If we do not set cudaDeviceId in new thread, the default cudaDeviceId will be 0,
# Which may cost hundreds of MB of GPU memory on CUDAPlace(0) if calling some cuda
# APIs in this thread.
core.set_current_thread_name("Dataloader_" + str(id(self)))
_set_expected_place(legacy_expected_place)
while not self._thread_done_event.is_set():
......
......@@ -477,6 +477,7 @@ def _py_reader(capacity,
def __provider_thread__(legacy_expected_place):
try:
# See _DataLoaderIterSingleProcess._thread_loop() for why set expected place here.
_set_expected_place(legacy_expected_place)
for tensors in func():
......
......@@ -1126,6 +1126,7 @@ class DygraphGeneratorLoader(DataLoaderBase):
def _reader_thread_loop_for_multiprocess(self, legacy_expected_place):
# See _DataLoaderIterSingleProcess._thread_loop() for why set expected place here.
core.set_current_thread_name("Dataloader_" + str(id(self)))
_set_expected_place(legacy_expected_place)
while not self._thread_done_event.is_set():
......@@ -1169,6 +1170,7 @@ class DygraphGeneratorLoader(DataLoaderBase):
def _reader_thread_loop_for_singleprocess(self, legacy_expected_place):
try:
# See _DataLoaderIterSingleProcess._thread_loop() for why set expected place here.
core.set_current_thread_name("Dataloader_" + str(id(self)))
_set_expected_place(legacy_expected_place)
for sample in self._batch_reader():
......@@ -1419,6 +1421,7 @@ class GeneratorLoader(DataLoaderBase):
def __thread_main__(legacy_expected_place):
try:
# See _DataLoaderIterSingleProcess._thread_loop() for why set expected place here.
core.set_current_thread_name("Dataloader_" + str(id(self)))
_set_expected_place(legacy_expected_place)
while not self._queue.wait_for_inited(1):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册