Skip to content

Commit 1a9602d

Browse files
ezyangfacebook-github-bot
authored andcommitted
Delete caffe2_cuda_full_device_control (pytorch#14283)
Summary: Pull Request resolved: pytorch#14283 According to Yangqing, this code was only used by us to do some end-to-end performance experiments on the impact of cudaSetDevice and cudaGetDevice. Now that the frameworks are merged, there are a lot of bare calls to those functions which are not covered by this flag. It doesn't seem like a priority to restore this functionality, so I am going to delete it for now. If you want to bring it back, you'll have to make all get/set calls go through this particular interfaces. Reviewed By: dzhulgakov Differential Revision: D13156472 fbshipit-source-id: 4c6d2cc89ab5ae13f7c816f43729b577e1bd985c
1 parent 8617b78 commit 1a9602d

File tree

2 files changed

+4
-48
lines changed

2 files changed

+4
-48
lines changed

caffe2/core/common_gpu.cc

+4-32
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@
1010
#include "caffe2/core/init.h"
1111
#include "caffe2/core/logging.h"
1212

13-
C10_DEFINE_bool(
14-
caffe2_cuda_full_device_control,
15-
false,
16-
"If true, assume all the cudaSetDevice and cudaGetDevice calls will be "
17-
"controlled by Caffe2, and non-Caffe2 code will ensure that the entry and "
18-
"exit point has the same cuda device. Under the hood, Caffe2 will use "
19-
"thread local variables to cache the device, in order to speed up set and "
20-
"get device calls. This is an experimental feature that may have non "
21-
"trivial side effects, so use it with care and only enable it if you are "
22-
"absolutely sure. Also, this flag should not be changed after the program "
23-
"initializes.");
24-
2513
namespace caffe2 {
2614

2715
int NumCudaDevices() {
@@ -89,8 +77,6 @@ int NumCudaDevices() {
8977

9078
namespace {
9179
int gDefaultGPUID = 0;
92-
// Only used when FLAGS_caffe2_cuda_full_device_control is set true.
93-
thread_local int gCurrentDevice = -1;
9480
} // namespace
9581

9682
void SetDefaultGPUID(const int deviceid) {
@@ -108,27 +94,13 @@ void SetDefaultGPUID(const int deviceid) {
10894
int GetDefaultGPUID() { return gDefaultGPUID; }
10995

11096
int CaffeCudaGetDevice() {
111-
if (FLAGS_caffe2_cuda_full_device_control) {
112-
if (gCurrentDevice < 0) {
113-
CUDA_ENFORCE(cudaGetDevice(&gCurrentDevice));
114-
}
115-
return gCurrentDevice;
116-
} else {
117-
int gpu_id = 0;
118-
CUDA_ENFORCE(cudaGetDevice(&gpu_id));
119-
return gpu_id;
120-
}
97+
int gpu_id = 0;
98+
CUDA_ENFORCE(cudaGetDevice(&gpu_id));
99+
return gpu_id;
121100
}
122101

123102
void CaffeCudaSetDevice(const int id) {
124-
if (FLAGS_caffe2_cuda_full_device_control) {
125-
if (gCurrentDevice != id) {
126-
CUDA_ENFORCE(cudaSetDevice(id));
127-
}
128-
gCurrentDevice = id;
129-
} else {
130-
CUDA_ENFORCE(cudaSetDevice(id));
131-
}
103+
CUDA_ENFORCE(cudaSetDevice(id));
132104
}
133105

134106
int GetGPUIDForPointer(const void* ptr) {

caffe2/core/context_gpu_test.cc

-16
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#include "caffe2/core/context_gpu.h"
88
#include <gtest/gtest.h>
99

10-
C10_DECLARE_bool(caffe2_cuda_full_device_control);
11-
1210
namespace caffe2 {
1311

1412
TEST(CUDATest, HasCudaRuntime) {
@@ -35,20 +33,6 @@ TEST(CUDAContextTest, TestSetGetDeviceWithoutCaffeMode) {
3533
}
3634
}
3735

38-
TEST(CUDAContextTest, TestSetGetDeviceWithCaffeMode) {
39-
// For a while, set full device control to be true.
40-
FLAGS_caffe2_cuda_full_device_control = true;
41-
for (int i = 0; i < NumCudaDevices(); ++i) {
42-
CaffeCudaSetDevice(i);
43-
EXPECT_EQ(CaffeCudaGetDevice(), i);
44-
}
45-
for (int i = NumCudaDevices() - 1; i >= 0; --i) {
46-
CaffeCudaSetDevice(i);
47-
EXPECT_EQ(CaffeCudaGetDevice(), i);
48-
}
49-
FLAGS_caffe2_cuda_full_device_control = false;
50-
}
51-
5236
TEST(CUDAContextTest, MemoryPoolAllocateDealloc) {
5337
if (!HasCudaGPU())
5438
return;

0 commit comments

Comments
 (0)