Skip to content

Commit efd3726

Browse files
authored
remove unused place (#6972)
* remove unused place * fix ci
1 parent ebf0d9e commit efd3726

8 files changed

Lines changed: 9 additions & 73 deletions

File tree

paddle/operators/math/math_function.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,6 @@ void set_constant_with_place<platform::CPUPlace>(
277277
TensorSetConstantCPU(tensor, value));
278278
}
279279

280-
template <>
281-
void set_constant_with_place<platform::MKLDNNPlace>(
282-
const platform::DeviceContext& context, framework::Tensor* tensor,
283-
float value) {
284-
framework::VisitDataType(framework::ToDataType(tensor->type()),
285-
TensorSetConstantCPU(tensor, value));
286-
}
287-
288280
struct TensorSetConstantWithPlace : public boost::static_visitor<void> {
289281
TensorSetConstantWithPlace(const platform::DeviceContext& context,
290282
framework::Tensor* tensor, float value)

paddle/operators/math/math_function.cu

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,6 @@ void set_constant_with_place<platform::CUDAPlace>(
273273
TensorSetConstantGPU(context, tensor, value));
274274
}
275275

276-
template <>
277-
void set_constant_with_place<platform::CUDNNPlace>(
278-
const platform::DeviceContext& context, framework::Tensor* tensor,
279-
float value) {
280-
set_constant_with_place<platform::CUDAPlace>(context, tensor, value);
281-
}
282-
283276
template struct RowwiseAdd<platform::CUDADeviceContext, float>;
284277
template struct RowwiseAdd<platform::CUDADeviceContext, double>;
285278
template struct ColwiseSum<platform::CUDADeviceContext, float>;

paddle/platform/device_context.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,18 @@ cudnnHandle_t CUDADeviceContext::cudnn_handle() const { return cudnn_handle_; }
178178

179179
cudaStream_t CUDADeviceContext::stream() const { return stream_; }
180180

181-
CUDNNDeviceContext::CUDNNDeviceContext(CUDNNPlace place)
182-
: CUDADeviceContext(place), place_(place) {
181+
CUDNNDeviceContext::CUDNNDeviceContext(CUDAPlace place)
182+
: CUDADeviceContext(place) {
183183
PADDLE_ENFORCE(dynload::cudnnCreate(&cudnn_handle_));
184184
PADDLE_ENFORCE(dynload::cudnnSetStream(cudnn_handle_, stream()));
185185
}
186186

187187
CUDNNDeviceContext::~CUDNNDeviceContext() {
188-
SetDeviceId(place_.device);
188+
SetDeviceId(boost::get<CUDAPlace>(GetPlace()).device);
189189
Wait();
190190
PADDLE_ENFORCE(dynload::cudnnDestroy(cudnn_handle_));
191191
}
192192

193-
Place CUDNNDeviceContext::GetPlace() const { return CUDNNPlace(); }
194-
195193
cudnnHandle_t CUDNNDeviceContext::cudnn_handle() const { return cudnn_handle_; }
196194

197195
#endif

paddle/platform/device_context.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,14 @@ class CUDADeviceContext : public DeviceContext {
9292

9393
class CUDNNDeviceContext : public CUDADeviceContext {
9494
public:
95-
explicit CUDNNDeviceContext(CUDNNPlace place);
95+
explicit CUDNNDeviceContext(CUDAPlace place);
9696
virtual ~CUDNNDeviceContext();
9797

98-
/*! \brief Return place in the device context. */
99-
Place GetPlace() const final;
100-
10198
/*! \brief Return cudnn handle in the device context. */
10299
cudnnHandle_t cudnn_handle() const;
103100

104101
private:
105102
cudnnHandle_t cudnn_handle_;
106-
CUDNNPlace place_;
107103
};
108104

109105
#endif

paddle/platform/device_context_test.cu

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ TEST(Device, CUDADeviceContext) {
5151

5252
TEST(Device, CUDNNDeviceContext) {
5353
using paddle::platform::CUDNNDeviceContext;
54-
using paddle::platform::CUDNNPlace;
54+
using paddle::platform::CUDAPlace;
5555
if (paddle::platform::dynload::HasCUDNN()) {
5656
int count = paddle::platform::GetCUDADeviceCount();
5757
for (int i = 0; i < count; ++i) {
58-
CUDNNDeviceContext* device_context =
59-
new CUDNNDeviceContext(CUDNNPlace(i));
58+
CUDNNDeviceContext* device_context = new CUDNNDeviceContext(CUDAPlace(i));
6059
cudnnHandle_t cudnn_handle = device_context->cudnn_handle();
6160
ASSERT_NE(nullptr, cudnn_handle);
6261
ASSERT_NE(nullptr, device_context->stream());

paddle/platform/place.cc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class PlacePrinter : public boost::static_visitor<> {
2323
public:
2424
explicit PlacePrinter(std::ostream &os) : os_(os) {}
2525
void operator()(const CPUPlace &) { os_ << "CPUPlace"; }
26-
void operator()(const MKLDNNPlace &) { os_ << "MKLDNNPlace"; }
2726
void operator()(const CUDAPlace &p) {
2827
os_ << "CUDAPlace(" << p.device << ")";
2928
}
@@ -41,18 +40,12 @@ const Place &get_place() { return the_default_place; }
4140

4241
const CUDAPlace default_gpu() { return CUDAPlace(0); }
4342
const CPUPlace default_cpu() { return CPUPlace(); }
44-
const MKLDNNPlace default_mkldnn() { return MKLDNNPlace(); }
4543

4644
bool is_gpu_place(const Place &p) {
4745
return boost::apply_visitor(IsCUDAPlace(), p);
4846
}
49-
bool is_cpu_place(const Place &p) {
50-
return !is_gpu_place(p) && !is_mkldnn_place(p);
51-
}
5247

53-
bool is_mkldnn_place(const Place &p) {
54-
return boost::apply_visitor(IsMKLDNNPlace(), p);
55-
}
48+
bool is_cpu_place(const Place &p) { return !is_gpu_place(p); }
5649

5750
bool places_are_same_class(const Place &p1, const Place &p2) {
5851
return p1.which() == p2.which();

paddle/platform/place.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ struct CPUPlace {
3131
inline bool operator!=(const CPUPlace &) const { return false; }
3232
};
3333

34-
struct MKLDNNPlace {
35-
MKLDNNPlace() {}
36-
37-
// needed for variant equality comparison
38-
inline bool operator==(const MKLDNNPlace &) const { return true; }
39-
inline bool operator!=(const MKLDNNPlace &) const { return false; }
40-
};
41-
4234
struct CUDAPlace {
4335
CUDAPlace() : CUDAPlace(0) {}
4436
explicit CUDAPlace(int d) : device(d) {}
@@ -53,37 +45,21 @@ struct CUDAPlace {
5345
int device;
5446
};
5547

56-
struct CUDNNPlace : public CUDAPlace {
57-
CUDNNPlace() : CUDAPlace() {}
58-
explicit CUDNNPlace(int d) : CUDAPlace(d) {}
59-
};
60-
6148
struct IsCUDAPlace : public boost::static_visitor<bool> {
6249
bool operator()(const CPUPlace &) const { return false; }
63-
bool operator()(const MKLDNNPlace &) const { return false; }
6450
bool operator()(const CUDAPlace &gpu) const { return true; }
65-
bool operator()(const CUDNNPlace &) const { return true; }
66-
};
67-
68-
struct IsMKLDNNPlace : public boost::static_visitor<bool> {
69-
bool operator()(const MKLDNNPlace &) const { return true; }
70-
bool operator()(const CPUPlace &) const { return false; }
71-
bool operator()(const CUDAPlace &) const { return false; }
72-
bool operator()(const CUDNNPlace &) const { return false; }
7351
};
7452

75-
typedef boost::variant<CUDNNPlace, CUDAPlace, CPUPlace, MKLDNNPlace> Place;
53+
typedef boost::variant<CUDAPlace, CPUPlace> Place;
7654

7755
void set_place(const Place &);
7856
const Place &get_place();
7957

8058
const CUDAPlace default_gpu();
8159
const CPUPlace default_cpu();
82-
const MKLDNNPlace default_mkldnn();
8360

8461
bool is_gpu_place(const Place &);
8562
bool is_cpu_place(const Place &);
86-
bool is_mkldnn_place(const Place &);
8763
bool places_are_same_class(const Place &, const Place &);
8864

8965
std::ostream &operator<<(std::ostream &, const Place &);

paddle/platform/place_test.cc

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,26 @@
55
TEST(Place, Equality) {
66
paddle::platform::CPUPlace cpu;
77
paddle::platform::CUDAPlace g0(0), g1(1), gg0(0);
8-
paddle::platform::CUDNNPlace d0(0), d1(1), dd0(0);
98

109
EXPECT_EQ(cpu, cpu);
1110
EXPECT_EQ(g0, g0);
1211
EXPECT_EQ(g1, g1);
1312
EXPECT_EQ(g0, gg0);
14-
EXPECT_EQ(d0, dd0);
1513

1614
EXPECT_NE(g0, g1);
17-
EXPECT_NE(d0, d1);
1815

1916
EXPECT_TRUE(paddle::platform::places_are_same_class(g0, gg0));
2017
EXPECT_FALSE(paddle::platform::places_are_same_class(g0, cpu));
21-
22-
EXPECT_TRUE(paddle::platform::is_gpu_place(d0));
23-
EXPECT_FALSE(paddle::platform::places_are_same_class(g0, d0));
2418
}
2519

2620
TEST(Place, Default) {
2721
EXPECT_TRUE(paddle::platform::is_gpu_place(paddle::platform::get_place()));
2822
EXPECT_TRUE(paddle::platform::is_gpu_place(paddle::platform::default_gpu()));
2923
EXPECT_TRUE(paddle::platform::is_cpu_place(paddle::platform::default_cpu()));
30-
EXPECT_TRUE(
31-
paddle::platform::is_mkldnn_place(paddle::platform::default_mkldnn()));
3224

25+
EXPECT_FALSE(paddle::platform::is_cpu_place(paddle::platform::get_place()));
3326
paddle::platform::set_place(paddle::platform::CPUPlace());
3427
EXPECT_TRUE(paddle::platform::is_cpu_place(paddle::platform::get_place()));
35-
36-
paddle::platform::set_place(paddle::platform::MKLDNNPlace());
37-
EXPECT_FALSE(paddle::platform::is_cpu_place(paddle::platform::get_place()));
38-
EXPECT_TRUE(paddle::platform::is_mkldnn_place(paddle::platform::get_place()));
3928
}
4029

4130
TEST(Place, Print) {

0 commit comments

Comments
 (0)