Skip to content

Commit a6edeb3

Browse files
committed
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into feature/clean_blas
2 parents caa4027 + 73650a8 commit a6edeb3

File tree

83 files changed

+1900
-672
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1900
-672
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ RUN apt-get update && \
3232
automake locales clang-format swig doxygen cmake \
3333
liblapack-dev liblapacke-dev \
3434
clang-3.8 llvm-3.8 libclang-3.8-dev \
35-
net-tools libtool && \
35+
net-tools libtool ccache && \
3636
apt-get clean -y
3737

3838
# Install Go and glide
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
# Update to point to the source file.
4+
VGG_SRC="vgg16_fluid.py"
5+
6+
export TRAINING_ROLE=PSERVER
7+
export TRAINERS=2
8+
export POD_IP=127.0.0.1
9+
export PADDLE_INIT_PORT=6174
10+
MKL_NUM_THREADS=1 python -u ${VGG_SRC} --local 0 --ps_host=127.0.0.1:6174 --trainer_hosts=127.0.0.1:6174 &
11+
12+
# Need to wait for the ps to start first.
13+
sleep 10
14+
echo "done start ps"
15+
16+
export TRAINING_ROLE=TRAINER
17+
export TRAINERS=2
18+
export POD_IP=127.0.0.1
19+
export PADDLE_INIT_PORT=6174
20+
CUDA_VISIBLE_DEVICES=4 MKL_NUM_THREADS=1 python -u ${VGG_SRC} --local 0 --ps_host=127.0.0.1:6174 --trainer_hosts=127.0.0.1:6174 --device=GPU --task_index=0 &
21+
CUDA_VISIBLE_DEVICES=5 MKL_NUM_THREADS=1 python -u ${VGG_SRC} --local 0 --ps_host=127.0.0.1:6174 --trainer_hosts=127.0.0.1:6174 --device=GPU --task_index=1 &

benchmark/cluster/vgg16/vgg16_fluid.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,19 @@ def train_loop(exe, trainer_prog):
200200
num_samples += len(data)
201201
train_pass_acc.add(value=acc, weight=b_size)
202202
print(
203-
"Pass = %d, Iters = %d, Loss = %f, Accuracy = %f, Speed = %.2f img/s"
204-
% (pass_id, iters, loss, acc,
205-
len(data) / (time.time() - ts))
203+
"Task:%d Pass = %d, Iters = %d, Loss = %f, Accuracy = %f, "
204+
"Speed = %.2f img/s " % (args.task_index, pass_id, iters,
205+
loss, acc,
206+
len(data) / (time.time() - ts))
206207
) # The accuracy is the accumulation of batches, but not the current batch.
207208

208209
pass_elapsed = time.time() - start_time
209210
pass_train_acc = train_pass_acc.eval()
210211
pass_test_acc = test(exe)
211-
print(
212-
"Pass = %d, Training performance = %f imgs/s, Train accuracy = %f, Test accuracy = %f\n"
213-
% (pass_id, num_samples / pass_elapsed, pass_train_acc,
214-
pass_test_acc))
212+
print("Task:%d Pass = %d, Training performance = %f imgs/s, "
213+
"Train accuracy = %f, Test accuracy = %f\n" %
214+
(args.task_index, pass_id, num_samples / pass_elapsed,
215+
pass_train_acc, pass_test_acc))
215216

216217
if args.local:
217218
# Parameter initialization
@@ -239,8 +240,6 @@ def train_loop(exe, trainer_prog):
239240

240241
t = fluid.DistributeTranspiler()
241242
t.transpile(
242-
optimize_ops,
243-
params_grads,
244243
trainer_id=args.task_index,
245244
pservers=args.ps_hosts,
246245
trainers=trainers)

paddle/capi/Matrix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ paddle_error paddle_matrix_get_row(paddle_matrix mat,
108108
paddle_error paddle_matrix_get_shape(paddle_matrix mat,
109109
uint64_t* height,
110110
uint64_t* width) {
111-
if (mat == nullptr) return kPD_NULLPTR;
111+
if (mat == nullptr || cast(mat)->mat == nullptr) return kPD_NULLPTR;
112112
if (height != nullptr) {
113113
*height = cast(mat)->mat->getHeight();
114114
}

paddle/cuda/include/hl_base.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

15-
#ifndef HL_BASE_H_
16-
#define HL_BASE_H_
15+
#pragma once
1716

1817
#include <cstddef>
1918

@@ -207,8 +206,8 @@ typedef struct {
207206

208207
#ifdef __NVCC__
209208

210-
#include "cuda_runtime.h"
211-
#include "hl_cuda.h"
209+
#include <cuda_runtime.h>
210+
#include "paddle/cuda/include/hl_cuda.h"
212211
#include "paddle/utils/Logging.h"
213212

214213
extern __thread bool g_sync_flag;
@@ -228,6 +227,19 @@ extern __thread cudaStream_t default_stream;
228227
<< "CUDA error: " << hl_get_device_error_string((size_t)err); \
229228
}
230229

231-
#endif /* __NVCC__ */
230+
// __shfl has been deprecated as of CUDA 9.0.
231+
#if CUDA_VERSION < 9000
232+
template <typename T>
233+
__forceinline__ __device__ T
234+
__shfl_sync(unsigned, T val, int src_line, int width) {
235+
return __shfl(val, src_line, width);
236+
}
232237

233-
#endif /* HL_BASE_H_ */
238+
#define CREATE_SHFL_MASK(mask, predicate) mask = 0u;
239+
#else
240+
#define FULL_WARP_MASK 0xFFFFFFFF
241+
#define CREATE_SHFL_MASK(mask, predicate) \
242+
mask = __ballot_sync(FULL_WARP_MASK, (predicate))
243+
#endif
244+
245+
#endif // __NVCC__

paddle/cuda/src/hl_cuda_lstm.cu

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,15 @@ void hl_lstm_parallel_forward(real *gateValue,
341341
}
342342

343343
__device__ __forceinline__ void transpose_32x32(real a[], const int idx) {
344-
int addr = idx % 32;
344+
const int warp_size = 32;
345+
int addr = idx % warp_size;
346+
unsigned mask = 0u;
347+
CREATE_SHFL_MASK(mask, addr < warp_size);
345348
#pragma unroll
346349
for (int k = 1; k < 32; k++) {
347350
// rSrc[k] = __shfl_sync(rSrc[k], (threadIdx.x + k) % 32, 32);
348-
addr = __shfl_sync(addr, (idx + 1) % 32, 32);
349-
a[k] = __shfl_sync(a[k], addr, 32);
351+
addr = __shfl_sync(mask, addr, (idx + 1) % 32, 32);
352+
a[k] = __shfl_sync(mask, a[k], addr, 32);
350353
}
351354

352355
#pragma unroll
@@ -360,10 +363,11 @@ __device__ __forceinline__ void transpose_32x32(real a[], const int idx) {
360363
}
361364

362365
addr = (32 - idx) % 32;
366+
CREATE_SHFL_MASK(mask, idx % 32 < warp_size);
363367
#pragma unroll
364368
for (int k = 0; k < 32; k++) {
365-
a[k] = __shfl_sync(a[k], addr, 32);
366-
addr = __shfl_sync(addr, (idx + 31) % 32, 32);
369+
a[k] = __shfl_sync(mask, a[k], addr, 32);
370+
addr = __shfl_sync(mask, addr, (idx + 31) % 32, 32);
367371
}
368372
}
369373

paddle/cuda/src/hl_top_k.cu

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,16 @@ __device__ __forceinline__ void blockReduce(Pair* shTopK,
244244
if (--beamSize == 0) break;
245245
__syncthreads();
246246

247+
unsigned mask = 0u;
248+
// CREATE_SHFL_MASK(mask, tid < len);
249+
247250
if (tid == maxId[0]) {
248251
if (beam < maxLength) {
249252
shTopK[tid] = topK[beam];
250253
}
251254
}
252255
if (maxId[0] / 32 == warp) {
253-
if (__shfl_sync(beam, (maxId[0]) % 32, 32) == maxLength) break;
256+
if (__shfl_sync(mask, beam, (maxId[0]) % 32, 32) == maxLength) break;
254257
}
255258
}
256259
}

paddle/fluid/framework/details/multi_devices_graph_builder.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ MultiDevSSAGraphBuilder::MultiDevSSAGraphBuilder(
3434
const std::vector<platform::Place> &places,
3535
const std::string &loss_var_name,
3636
const std::unordered_set<std::string> &params,
37-
const std::vector<Scope *> &local_scopes, bool skip_scale_loss,
37+
const std::vector<Scope *> &local_scopes, bool use_default_grad_scale,
3838
platform::NCCLContextMap *nccl_ctxs)
3939
: loss_var_name_(loss_var_name),
4040
places_(places),
@@ -45,15 +45,15 @@ MultiDevSSAGraphBuilder::MultiDevSSAGraphBuilder(
4545
const std::vector<platform::Place> &places,
4646
const std::string &loss_var_name,
4747
const std::unordered_set<std::string> &params,
48-
const std::vector<Scope *> &local_scopes, bool skip_scale_loss)
48+
const std::vector<Scope *> &local_scopes, bool use_default_grad_scale)
4949
: loss_var_name_(loss_var_name),
5050
places_(places),
5151
local_scopes_(local_scopes) {
5252
#endif
5353
for (auto &p : params) {
5454
grad_names_.insert(GradVarName(p));
5555
}
56-
skip_scale_loss_ = skip_scale_loss;
56+
use_default_grad_scale_ = use_default_grad_scale;
5757
}
5858

5959
void MultiDevSSAGraphBuilder::CreateOpHandleIOs(SSAGraph *result,
@@ -126,8 +126,8 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
126126
} else if (IsDistTrainOp(*op, send_op)) {
127127
CreateComputationalOps(&result, *op, 1);
128128
} else if (IsScaleLossOp(*op)) {
129-
// user can customize loss@grad if skip_scale_loss_
130-
if (!skip_scale_loss_) {
129+
// user can customize loss@grad if not use_default_grad_scale_
130+
if (use_default_grad_scale_) {
131131
CreateScaleLossGradOp(&result);
132132
}
133133
is_forwarding = false;

paddle/fluid/framework/details/multi_devices_graph_builder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class MultiDevSSAGraphBuilder : public SSAGraphBuilder {
4141
const std::string &loss_var_name,
4242
const std::unordered_set<std::string> &params,
4343
const std::vector<Scope *> &local_scopes,
44-
bool skip_scale_loss);
44+
bool use_default_grad_scale);
4545
#endif
4646

4747
std::unique_ptr<SSAGraph> Build(const ProgramDesc &program) const override;
@@ -59,7 +59,7 @@ class MultiDevSSAGraphBuilder : public SSAGraphBuilder {
5959
#ifdef PADDLE_WITH_CUDA
6060
platform::NCCLContextMap *nccl_ctxs_;
6161
#endif
62-
bool skip_scale_loss_;
62+
bool use_default_grad_scale_;
6363

6464
bool IsScaleLossOp(const OpDesc &op) const;
6565

paddle/fluid/framework/lod_tensor_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,11 @@ TEST(LoDTensor, RecordIO) {
255255
std::unique_ptr<std::istream> stream_ptr(stream);
256256
recordio::Scanner scanner(std::move(stream_ptr));
257257
auto tensors = ReadFromRecordIO(&scanner, ctx);
258-
ASSERT_EQ(tensors.size(), 2);
258+
ASSERT_EQ(tensors.size(), static_cast<size_t>(2));
259259
assert_tensor_ok(tensors[0]);
260260
assert_tensor_ok(tensors[1]);
261261
tensors = ReadFromRecordIO(&scanner, ctx);
262-
ASSERT_EQ(tensors.size(), 2);
262+
ASSERT_EQ(tensors.size(), static_cast<size_t>(2));
263263
assert_tensor_ok(tensors[0]);
264264
assert_tensor_ok(tensors[1]);
265265
}

0 commit comments

Comments
 (0)