Skip to content

Commit 73831b0

Browse files
committed
push for test
1 parent c25c494 commit 73831b0

File tree

5 files changed

+41
-20
lines changed

5 files changed

+41
-20
lines changed

paddle/fluid/platform/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ endif()
151151

152152
cc_test(init_test SRCS init_test.cc DEPS device_context)
153153

154-
cc_library(device_event SRCS device_event.cc DEPS place enforce device_context)
154+
cc_library(device_event SRCS device_event.cc DEPS place enforce device_context op_registry)
155155
cc_library(device_event_gpu SRCS device_event_gpu.cc DEPS device_event)
156156

157157

paddle/fluid/platform/device_event.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717
namespace paddle {
1818
namespace platform {
19+
#define PD_CX __attribute__((visibility("default")))
1920

20-
EventCreateFunction DeviceEvent::event_creator_[MaxDeviceTypes];
21-
EventRecordFunction DeviceEvent::event_recorder_[MaxDeviceTypes];
22-
EventQueryFunction DeviceEvent::event_querier_[MaxDeviceTypes];
21+
PD_CX EventCreateFunction DeviceEvent::event_creator_[MaxDeviceTypes];
22+
PD_CX EventRecordFunction DeviceEvent::event_recorder_[MaxDeviceTypes];
23+
PD_CX EventQueryFunction DeviceEvent::event_querier_[MaxDeviceTypes];
2324

2425
} // namespace platform
2526
} // namespace paddle

paddle/fluid/platform/device_event.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414
#pragma once
1515
#include <memory>
16+
#include "paddle/fluid/framework/op_registry.h"
1617
#include "paddle/fluid/platform/device_context.h"
1718
#include "paddle/fluid/platform/enforce.h"
1819
#include "paddle/fluid/platform/place.h"
@@ -79,7 +80,7 @@ class DeviceEvent {
7980
event_querier_[type_],
8081
platform::errors::Unavailable(
8182
"event_querier_[%d] shall not be nullptr.", type_));
82-
event_querier_[type_](this);
83+
return event_querier_[type_](this);
8384
}
8485

8586
void InitEvent(std::shared_ptr<void> event) { event_ = event; }
@@ -114,14 +115,24 @@ struct EventCreateFunctionRegisterer {
114115
explicit EventCreateFunctionRegisterer(EventCreateFunction func) {
115116
auto type_idx = DeviceTypeToId(device_type);
116117
DeviceEvent::event_creator_[type_idx] = func;
118+
VLOG(2) << "register creator " << type_idx << " with "
119+
<< DeviceEvent::event_creator_[type_idx];
117120
}
121+
void Touch() {}
118122
};
119-
#define REGISTER_EVENT_CREATE_FUNCTION(device_type, func) \
120-
namespace { \
121-
static EventCreateFunctionRegisterer<device_type> \
122-
g_device_event_create_##type_idx(func); \
123+
124+
#define REGISTER_EVENT_CREATE_FUNCTION(device_type, func) \
125+
static ::paddle::platform::EventCreateFunctionRegisterer<device_type> \
126+
g_device_event_create_1(func); \
127+
int touch_g_device_event_create_1() { \
128+
g_device_event_create_1.Touch(); \
129+
return 0; \
123130
}
124131

132+
#define USE_EVENT(device_type) \
133+
extern int touch_g_device_event_create_1(); \
134+
UNUSED static int use_event_itself_1 = touch_g_device_event_create_1();
135+
125136
template <DeviceType device_type>
126137
struct EventRecordFunctionRegisterer {
127138
explicit EventRecordFunctionRegisterer(EventRecordFunction func) {

paddle/fluid/platform/device_event_gpu.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
#include "paddle/fluid/platform/device_event.h"
1616
#include "paddle/fluid/platform/event.h"
1717

18+
#ifdef PADDLE_WITH_CUDA
1819
namespace paddle {
1920
namespace platform {
20-
#ifdef PADDLE_WITH_CUDA
2121
struct CUDADeviceEventWrapper {
2222
explicit CUDADeviceEventWrapper(const DeviceOption& dev_opt) {
2323
PADDLE_ENFORCE_EQ(
@@ -56,10 +56,12 @@ bool DeviceEventQueryCUDA(const DeviceEvent* event) {
5656
return wrapper->inner_event_.Query();
5757
}
5858

59-
REGISTER_EVENT_CREATE_FUNCTION(DeviceType::CUDA, DeviceEventCreateCUDA)
60-
REGISTER_EVENT_RECORD_FUNCTION(DeviceType::CUDA, DeviceEventRecordCUDA)
61-
REGISTER_EVENT_QUERY_FUNCTION(DeviceType::CUDA, DeviceEventQueryCUDA)
59+
// REGISTER_EVENT_RECORD_FUNCTION(DeviceType::CUDA, DeviceEventRecordCUDA)
60+
// REGISTER_EVENT_QUERY_FUNCTION(DeviceType::CUDA, DeviceEventQueryCUDA)
6261

63-
#endif
6462
} // namespace platform
6563
} // namespace paddle
64+
65+
using ::paddle::platform::DeviceType::CUDA;
66+
REGISTER_EVENT_CREATE_FUNCTION(CUDA, paddle::platform::DeviceEventCreateCUDA)
67+
#endif

paddle/fluid/platform/device_event_test.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,28 @@
1717
#include "glog/logging.h"
1818
#include "gtest/gtest.h"
1919

20+
USE_EVENT(1);
21+
2022
#ifdef PADDLE_WITH_CUDA
21-
Test(DeviceEvent, GPU) {
23+
TEST(DeviceEvent, GPU) {
24+
VLOG(1) << "In Test";
2225
using paddle::platform::CUDAPlace;
2326
using paddle::platform::DeviceOption;
2427
using paddle::platform::DeviceEvent;
28+
using paddle::platform::DeviceContextPool;
29+
using paddle::platform::DeviceType;
2530

2631
auto& pool = DeviceContextPool::Instance();
2732
auto place = CUDAPlace(0);
28-
auto* context = pool.get(place);
29-
DeviceOption dev_opt(place.device);
33+
auto* context = pool.Get(place);
34+
int device_type = static_cast<int>(DeviceType::CUDA);
35+
DeviceOption dev_opt(device_type, place.device);
3036

3137
ASSERT_NE(context, nullptr);
3238
DeviceEvent event(dev_opt);
33-
event.Record(place, context);
34-
bool status = event.Query();
35-
ASSERT_EQ(status, true);
39+
ASSERT_NE(event.GetEvent().get(), nullptr);
40+
// event.Record(place, context);
41+
// bool status = event.Query();
42+
// ASSERT_EQ(status, true);
3643
}
3744
#endif

0 commit comments

Comments
 (0)