Skip to content

Commit d5cce78

Browse files
committed
remove native conv cpp impl in cpp operation/; rename github workflow stages
1 parent e5445a5 commit d5cce78

9 files changed

Lines changed: 43 additions & 6362 deletions

File tree

.asf.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ github:
2424
wiki: true
2525
# Enable issues on github
2626
issues: true
27+
# Enable settings on github
28+
settings: true

.github/workflows/conda.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ on:
2727

2828
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
2929
jobs:
30-
build-ubuntu-conda:
30+
build-pytest-on-cpu:
3131
runs-on: ubuntu-latest
3232

3333
steps:
@@ -36,5 +36,5 @@ jobs:
3636
run: conda install conda-build
3737
- name: conda-config
3838
run: conda config --add channels conda-forge && conda config --add channels nusdbsystem
39-
- name: build-singa-conda
39+
- name: build-pytest
4040
run: conda build tool/conda/singa

.github/workflows/macOS.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
# limitations under the License.
1616
#
1717

18-
name: macOS
18+
name: Native-MacOS
1919

2020
on:
2121
push:
2222
pull_request:
2323

2424
jobs:
25-
build-macOS-cpu:
25+
build-cpptest-cpu:
2626
runs-on: macos-latest
2727

2828
steps:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
# This is a basic workflow to help you get started with Actions
1919

20-
name: C++
20+
name: Native-Ubuntu
2121

2222
# Controls when the action will run. Triggers the workflow on push or pull request
2323
# events but only for the master branch
@@ -41,7 +41,7 @@ jobs:
4141
# - name: C++ test
4242
# run: build/bin/test_singa
4343

44-
build-ubuntu-oneDNN:
44+
build-cpptest-on-cpu:
4545
runs-on: ubuntu-latest
4646

4747
steps:

examples/onnx/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import tarfile
2222
import glob
2323
import onnx
24-
from onnx import numpy_helper
2524
import logging
2625
logging.basicConfig(level=logging.INFO, format='%(asctime)-15s %(message)s')
2726

@@ -41,7 +40,7 @@ def load_dataset(test_data_dir):
4140
onnx_tensor = onnx.TensorProto()
4241
with open(input_file, 'rb') as f:
4342
onnx_tensor.ParseFromString(f.read())
44-
inputs.append(numpy_helper.to_array(onnx_tensor))
43+
inputs.append(onnx.numpy_helper.to_array(onnx_tensor))
4544

4645
# load reference outputs
4746
ref_outputs = []
@@ -51,7 +50,7 @@ def load_dataset(test_data_dir):
5150
onnx_tensor = onnx.TensorProto()
5251
with open(output_file, 'rb') as f:
5352
onnx_tensor.ParseFromString(f.read())
54-
ref_outputs.append(numpy_helper.to_array(onnx_tensor))
53+
ref_outputs.append(onnx.numpy_helper.to_array(onnx_tensor))
5554
return inputs, ref_outputs
5655

5756

@@ -63,4 +62,3 @@ def check_exist_or_download(url):
6362
logging.info("Downloading %s" % url)
6463
urllib.request.urlretrieve(url, filename)
6564
return filename
66-

python/singa/sonnx.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@
2121

2222
import numpy as np
2323
import onnx.utils
24-
import onnx
24+
import onnx.save
25+
import onnx.load
2526
from onnx.backend.base import Backend, BackendRep
2627
from onnx import (checker, helper, numpy_helper, GraphProto, NodeProto,
27-
TensorProto, OperatorSetIdProto, optimizer, mapping)
28+
TensorProto, OperatorSetIdProto, optimizer, mapping,
29+
shape_inference)
2830
import warnings
2931

30-
from singa import device
31-
from . import singa_wrap as singa
32-
from . import autograd, layer
33-
from . import tensor
34-
from . import model
35-
from singa import utils
32+
import device
33+
import autograd
34+
import layer
35+
import tensor
36+
import model
37+
import utils
38+
from singa_wrap as singa
3639

3740
import collections
3841
OrderedDict = collections.OrderedDict
@@ -390,10 +393,9 @@ def _create_constantOfShape(cls, op, op_t):
390393
the onnx node
391394
"""
392395
node = cls._common_singa_tensor_to_onnx_node(op, op_t)
393-
tensor_type = onnx.TensorProto.FLOAT if isinstance(
394-
op.value, float) else onnx.TensorProto.INT32
395-
tensor_value = onnx.helper.make_tensor("value", tensor_type, [1],
396-
[op.value])
396+
tensor_type = TensorProto.FLOAT if isinstance(
397+
op.value, float) else TensorProto.INT32
398+
tensor_value = helper.make_tensor("value", tensor_type, [1], [op.value])
397399
node.attribute.extend([
398400
helper.make_attribute('value', tensor_value),
399401
])
@@ -1895,7 +1897,7 @@ def prepare(cls, model, device='CPU', **kwargs):
18951897
try:
18961898
model = onnx.utils.polish_model(model)
18971899
except IndexError as err:
1898-
model = onnx.shape_inference.infer_shapes(model)
1900+
model = shape_inference.infer_shapes(model)
18991901

19001902
# check the opset version and ir version
19011903
# SINGA supports opset version(11), ir version(1.6.0 -> 6)
@@ -2199,4 +2201,4 @@ def forward(self, *input, aux_output=(), **kwargs):
21992201
get_op = SingaBackend._onnx_node_to_singa_op
22002202
to_onnx = SingaFrontend.singa_to_onnx_model
22012203
save = onnx.save
2202-
load = onnx.load
2204+
load = onnx.load

setup.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@
5555
import io
5656
import sys
5757
import subprocess
58-
import textwrap
59-
import traceback
6058
import shutil
6159
import shlex
6260
from pathlib import Path
@@ -192,10 +190,8 @@ def generate_singa_config(with_cuda, with_nccl):
192190

193191

194192
def get_cpp_flags():
195-
last_err = None
196193
default_flags = ['-std=c++11', '-fPIC', '-g', '-O2', '-Wall', '-pthread']
197194
# avx_flags = [ '-mavx'] #'-mf16c',
198-
flags_to_try = []
199195
if sys.platform == 'darwin':
200196
# Darwin most likely will have Clang, which has libc++.
201197
return default_flags + ['-stdlib=libc++']

src/model/operation/convolution.cc

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
************************************************************/
2121
// #include "../layer/convolution.h"
2222

23-
#include <cctype>
24-
2523
#include "convolution.h"
2624

25+
#include <cctype>
26+
2727
namespace singa {
2828

2929
ConvHandle::ConvHandle(const Tensor &input,
@@ -188,7 +188,8 @@ Tensor CpuConvForward(const Tensor &x, Tensor &W, Tensor &b,
188188
{x.block(), W.block(), b.block()}, {output.block()}, "CpuConvForward");
189189

190190
return output;
191-
#else // cpp naive
191+
#else // cpp naive, error due to Im2col importing
192+
/*
192193
Shape w_shape = W.shape();
193194
Shape b_shape;
194195
if (ch.bias_term) b_shape = b.shape();
@@ -219,6 +220,7 @@ Tensor CpuConvForward(const Tensor &x, Tensor &W, Tensor &b,
219220
W.Reshape(w_shape);
220221
if (ch.bias_term) b.Reshape(b_shape);
221222
return output;
223+
*/
222224
#endif // USE_DNNL
223225
}
224226

@@ -284,6 +286,7 @@ Tensor CpuConvBackwardx(const Tensor &dy, Tensor &W, const Tensor &x,
284286
return dx;
285287

286288
#else // NOT USE_DNNL
289+
/* // error due to importing Col2im
287290
Shape w_shape = W.shape();
288291
W.Reshape(Shape{ch.num_filters, ch.col_height});
289292
@@ -303,6 +306,7 @@ Tensor CpuConvBackwardx(const Tensor &dy, Tensor &W, const Tensor &x,
303306
}
304307
W.Reshape(w_shape);
305308
return dx;
309+
*/
306310
#endif // USE_DNNL
307311
}
308312

@@ -372,10 +376,12 @@ Tensor CpuConvBackwardW(const Tensor &dy, const Tensor &x, const Tensor &W,
372376
{DNNL_ARG_DIFF_BIAS, conv_diff_bias_memory}});
373377
ctx->dnnl_stream.wait();
374378
},
375-
{x.block(), dy.block(), W.block()}, {dW.block(), ch.db->block()}, "CpuConvBackwardW");
379+
{x.block(), dy.block(), W.block()}, {dW.block(), ch.db->block()},
380+
"CpuConvBackwardW");
376381

377382
return dW;
378383
#else // native cpp
384+
/* // error due to importing Im2col
379385
Tensor dW;
380386
dW.ResetLike(W);
381387
dW.SetValue(0.0f);
@@ -398,6 +404,7 @@ Tensor CpuConvBackwardW(const Tensor &dy, const Tensor &x, const Tensor &W,
398404
}
399405
dW.Reshape(w_shape);
400406
return dW;
407+
*/
401408
#endif // USE_DNNL
402409
}
403410

@@ -598,7 +605,8 @@ Tensor GpuConvForward(const Tensor &x, const Tensor &W, const Tensor &b,
598605
cch.workspace_count * sizeof(float), &beta,
599606
cch.y_desc, outblock->mutable_data());
600607
},
601-
{x.block(), W.block()}, {output.block(), cch.workspace.block()}, "cudnnConvForward");
608+
{x.block(), W.block()}, {output.block(), cch.workspace.block()},
609+
"cudnnConvForward");
602610

603611
if (cch.bias_term) {
604612
Tensor outputFake(output);
@@ -634,7 +642,8 @@ Tensor GpuConvBackwardx(const Tensor &dy, const Tensor &W, const Tensor &x,
634642
cch.workspace_count * sizeof(float), &beta, cch.x_desc,
635643
dxblock->mutable_data());
636644
},
637-
{dy.block(), W.block()}, {dx.block(), cch.workspace.block()}, "cudnnConvolutionBackwardData");
645+
{dy.block(), W.block()}, {dx.block(), cch.workspace.block()},
646+
"cudnnConvolutionBackwardData");
638647

639648
return dx;
640649
}
@@ -658,7 +667,8 @@ Tensor GpuConvBackwardW(const Tensor &dy, const Tensor &x, const Tensor &W,
658667
cch.workspace_count * sizeof(float), &beta, cch.filter_desc,
659668
dwblock->mutable_data());
660669
},
661-
{dy.block(), x.block()}, {dW.block(), cch.workspace.block()}, "cudnnConvolutionBackwardFilter");
670+
{dy.block(), x.block()}, {dW.block(), cch.workspace.block()},
671+
"cudnnConvolutionBackwardFilter");
662672

663673
return dW;
664674
}

0 commit comments

Comments
 (0)