Browse Source

code review of gpu-array

tags/v1.5.0-rc1
zhou_lili 4 years ago
parent
commit
69a915d4eb
7 changed files with 21 additions and 19 deletions
  1. +1
    -1
      mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/dynamic_range_gpu_kernel.h
  2. +2
    -2
      mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/dynamic_shape_gpu_kernel.h
  3. +4
    -2
      mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/one_hot_gpu_kernel.h
  4. +1
    -1
      mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/slice_gpu_kernel.h
  5. +2
    -2
      mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/slice_grad_gpu_kernel.h
  6. +9
    -9
      mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/strided_slice_gpu_common.h
  7. +2
    -2
      mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/strided_slice_gpu_kernel.h

+ 1
- 1
mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/dynamic_range_gpu_kernel.h View File

@@ -102,7 +102,7 @@ class DynamicRangeGpuKernel : public GpuKernel {
"cudaStreamSynchronize failed");

std::vector<TypeId> output_type = {AnfAlgo::GetOutputInferDataType(kernel_node_.lock(), 0)};
std::vector<std::vector<size_t>> output_shape = {{(size_t)output_shape_}};
std::vector<std::vector<size_t>> output_shape = {{static_cast<size_t>(output_shape_)}};
AnfAlgo::SetOutputInferTypeAndShape(output_type, output_shape, kernel_node_.lock().get());
}



+ 2
- 2
mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/dynamic_shape_gpu_kernel.h View File

@@ -75,8 +75,8 @@ class DynamicShapeGpuKernel : public GpuKernel {
}

void ResetResource() noexcept override {
input_size_ = -1;
output_size_ = -1;
input_size_ = 0;
output_size_ = 0;
prev_node_output_shape_.clear();
input_size_list_.clear();
output_size_list_.clear();


+ 4
- 2
mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/one_hot_gpu_kernel.h View File

@@ -49,8 +49,10 @@ class OneHotGpuFwdKernel : public GpuKernel {
auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
auto output_shape = AnfAlgo::GetOutputInferShape(kernel_node, 0);
int64_t input_dims = static_cast<int64_t>(input_shape.size());
if (axis >= input_dims) {
MS_LOG(ERROR) << "invalid one hot axis value: " << axis << " for input dims size: " << input_shape.size();
int64_t output_dims = static_cast<int64_t>(output_shape.size());
if (axis >= input_dims || axis >= output_dims) {
MS_LOG(ERROR) << "invalid one hot axis value: " << axis << " for input dims size: " << input_shape.size()
<< " or output dims size: " << output_dims;
return false;
}
const int64_t default_axis = -1;


+ 1
- 1
mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/slice_gpu_kernel.h View File

@@ -146,7 +146,7 @@ class SliceGpuFwdKernel : public GpuKernel {
begin_ = GetAttr<std::vector<int64_t>>(kernel_node, "begin");

for (size_t i = 0; i < input_shape.size(); i++) {
if (input_shape[i] <= 0 || size_[i] <= 0) {
if (i >= size_.size() || input_shape[i] <= 0 || size_[i] <= 0) {
MS_LOG(WARNING) << "Slice output is null.";
is_null_input_ = true;
}


+ 2
- 2
mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/slice_grad_gpu_kernel.h View File

@@ -105,12 +105,12 @@ class SliceGradGpuKernel : public GpuKernel {
std::swap(size_[1], size_[2]);
}
for (size_t i = 0; i < begin_.size(); i++) {
if (begin_[i] < 0) {
if (begin_[i] < 0 && i < input_shape_.size()) {
begin_[i] = begin_[i] + input_shape_[i];
}
}
for (size_t i = 0; i < size_.size(); i++) {
if (size_[i] < 0) {
if (size_[i] < 0 && i < input_shape_.size()) {
size_[i] = (size_[i] + input_shape_[i]) > 0 ? (size_[i] + input_shape_[i]) : 0;
}
}


+ 9
- 9
mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/strided_slice_gpu_common.h View File

@@ -43,6 +43,10 @@ class StridedSliceGpuCommon {
strides_ = AnfAlgo::GetNodeAttr<std::vector<int64_t>>(kernel_node, "strides");

for (size_t i = 0; i < MAX_DIMS; i++) {
if (i >= input_shape_.size()) {
input_shape_.push_back(1);
}

if (i < begin_.size()) {
int64_t dim = input_shape_[i];
begin_[i] = std::min(begin_[i] < 0 ? std::max(begin_[i] + dim, static_cast<int64_t>(0)) : begin_[i], dim - 1);
@@ -60,10 +64,6 @@ class StridedSliceGpuCommon {
if (i >= strides_.size()) {
strides_.push_back(1);
}

if (i >= input_shape_.size()) {
input_shape_.push_back(1);
}
}
}

@@ -71,7 +71,7 @@ class StridedSliceGpuCommon {
auto begin_mask_int = AnfAlgo::GetNodeAttr<int64_t>(kernel_node, "begin_mask");
auto begin_mask = Dec2Bin(begin_mask_int);
for (size_t i = 0; i < begin_mask.size(); i++) {
if (begin_mask[i]) {
if (begin_mask[i] && i < MAX_DIMS) {
begin_[i] = 0;
}
}
@@ -79,7 +79,7 @@ class StridedSliceGpuCommon {
auto end_mask_int = AnfAlgo::GetNodeAttr<int64_t>(kernel_node, "end_mask");
auto end_mask = Dec2Bin(end_mask_int);
for (size_t j = 0; j < end_mask.size(); j++) {
if (end_mask[j]) {
if (end_mask[j] && j < MAX_DIMS) {
end_[j] = input_shape_[j];
}
}
@@ -87,7 +87,7 @@ class StridedSliceGpuCommon {
auto ellipsis_mask_int = AnfAlgo::GetNodeAttr<int64_t>(kernel_node, "ellipsis_mask");
auto ellipsis_mask = Dec2Bin(ellipsis_mask_int);
for (size_t k = 0; k < ellipsis_mask.size(); k++) {
if (ellipsis_mask[k]) {
if (ellipsis_mask[k] && k < MAX_DIMS) {
begin_[k] = 0;
end_[k] = input_shape_[k];
strides_[k] = 1;
@@ -97,7 +97,7 @@ class StridedSliceGpuCommon {
auto new_axis_mask_int = AnfAlgo::GetNodeAttr<int64_t>(kernel_node, "new_axis_mask");
auto new_axis_mask = Dec2Bin(new_axis_mask_int);
for (size_t l = 0; l < new_axis_mask.size(); l++) {
if (new_axis_mask[l]) {
if (new_axis_mask[l] && l < MAX_DIMS) {
begin_[l] = 0;
end_[l] = input_shape_[l];
strides_[l] = 1;
@@ -107,7 +107,7 @@ class StridedSliceGpuCommon {
auto shrink_axis_mask_int = AnfAlgo::GetNodeAttr<int64_t>(kernel_node, "shrink_axis_mask");
auto shrink_axis_mask = Dec2Bin(shrink_axis_mask_int);
for (size_t m = 0; m < shrink_axis_mask.size(); m++) {
if (shrink_axis_mask[m]) {
if (shrink_axis_mask[m] && m < MAX_DIMS) {
end_[m] = end_[m] > begin_[m] ? begin_[m] + 1 : begin_[m] - 1;
strides_[m] = end_[m] > begin_[m] ? 1 : -1;
}


+ 2
- 2
mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/strided_slice_gpu_kernel.h View File

@@ -65,13 +65,13 @@ class StridedSliceGpuKernel : public GpuKernel, public StridedSliceGpuCommon {
protected:
void InitSizeLists() override {
size_t size = sizeof(T);
for (size_t i = 0; i < MAX_DIMS; i++) {
for (size_t i = 0; i < input_shape_.size(); i++) {
size *= input_shape_[i];
}
input_size_list_.push_back(size);

size_t size1 = sizeof(T);
for (size_t i = 0; i < MAX_DIMS; i++) {
for (size_t i = 0; i < output_shape_.size(); i++) {
size1 *= output_shape_[i];
}
output_size_list_.push_back(size1);


Loading…
Cancel
Save