Merge pull request #450 from ijingo/master

SINGA-433 Preparation for V2.0 release
diff --git a/LICENSE b/LICENSE
index 9a119a7..d3358c1 100644
--- a/LICENSE
+++ b/LICENSE
@@ -296,6 +296,7 @@
 =====================================================================
 SINGA bundles the following under MIT license:
 cmake/ThirdParty/FindOpenCL.cmake
+Open Neural Network Exchange
 
 Copyright (c) 2010-2016 Institute for Microelectronics,
                         Institute for Analysis and Scientific Computing, TU Wien.
@@ -304,6 +305,9 @@
 is owned by The United States Government, and operated by UChicago Argonne, LLC
 under provision of a contract with the Department of Energy.
 
+Copyright (c) ONNX Project Contributors.
+All rights reserved.
+
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
@@ -419,3 +423,55 @@
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+=====================================================================
+SINGA bundles the following under Apache License v2.0:
+mkl-dnn
+
+Copyright 2017-2018 Intel Corporation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+
+=====================================================================
+SINGA bundles the following under Apache License v2.0:
+examples/imagenet/inception/convert.py
+
+Copyright 2016 The TensorFlow Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+
+=====================================================================
+SINGA bundles the following under New BSD license: 
+doc/en/docs/notebook/utils.py 
+
+Copyright (c) 2008–2013, Theano Development Team All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+        Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+        Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+        Neither the name of Theano nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ‘’AS IS’’ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
diff --git a/doc/_static/style.css b/doc/_static/style.css
index 86cc1f9..6a0bbc3 100644
--- a/doc/_static/style.css
+++ b/doc/_static/style.css
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
 .wy-nav-content {
     max-width: none;
 }
diff --git a/doc/en/docs/autograd.md b/doc/en/docs/autograd.md
index 6070629..f80f2cb 100644
--- a/doc/en/docs/autograd.md
+++ b/doc/en/docs/autograd.md
@@ -1,4 +1,24 @@
-# Autograd in Singa
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+
+
+# Autograd in Singa
 
 There are two typical ways to implement autograd, via symbolic differentiation like [Theano](http://deeplearning.net/software/theano/index.html) or reverse differentiation like [Pytorch](https://pytorch.org/docs/stable/notes/autograd.html). Singa follows Pytorch way, which records the computation graph and apply the backward propagation automatically after forward propagation. The autograd algorithm is explained in details [here](https://pytorch.org/docs/stable/notes/autograd.html). We explain the relevant modules in Singa and give an example to illustrate the usage. 
 
diff --git a/doc/en/docs/notebook/requirements.txt b/doc/en/docs/notebook/requirements.txt
index 21e293b..a128d1b 100644
--- a/doc/en/docs/notebook/requirements.txt
+++ b/doc/en/docs/notebook/requirements.txt
@@ -1,3 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
 matplotlib=2.0.0=np112py27_0
 nb_conda_kernels=2.0.0=py27_0
 nb_conda=2.0.0=py27_0
diff --git a/doc/en/docs/notebook/utils.py b/doc/en/docs/notebook/utils.py
index 3af9ec5..dd18964 100755
--- a/doc/en/docs/notebook/utils.py
+++ b/doc/en/docs/notebook/utils.py
@@ -21,9 +21,14 @@
     return ndar
 
 
-def tile_raster_images(X, img_shape, tile_shape, tile_spacing=(0, 0),
-                       scale_rows_to_unit_interval=True,
-                       output_pixel_vals=True):
+def tile_raster_images(
+    X,
+    img_shape,
+    tile_shape,
+    tile_spacing=(0, 0),
+    scale_rows_to_unit_interval=True,
+    output_pixel_vals=True,
+):
     """
     Transform an array with one flattened image per row, into an array in
     which images are reshaped and layed out like tiles on a floor.
@@ -76,17 +81,19 @@
         assert len(X) == 4
         # Create an output numpy ndarray to store the image
         if output_pixel_vals:
-            out_array = numpy.zeros((out_shape[0], out_shape[1], 4),
-                                    dtype='uint8')
+            out_array = numpy.zeros(
+                (out_shape[0], out_shape[1], 4), dtype="uint8"
+            )
         else:
-            out_array = numpy.zeros((out_shape[0], out_shape[1], 4),
-                                    dtype=X.dtype)
+            out_array = numpy.zeros(
+                (out_shape[0], out_shape[1], 4), dtype=X.dtype
+            )
 
-        #colors default to 0, alpha defaults to 1 (opaque)
+        # colors default to 0, alpha defaults to 1 (opaque)
         if output_pixel_vals:
             channel_defaults = [0, 0, 0, 255]
         else:
-            channel_defaults = [0., 0., 0., 1.]
+            channel_defaults = [0.0, 0.0, 0.0, 1.0]
 
         for i in range(4):
             if X[i] is None:
@@ -94,17 +101,21 @@
                 # dtype
                 dt = out_array.dtype
                 if output_pixel_vals:
-                    dt = 'uint8'
-                out_array[:, :, i] = numpy.zeros(
-                    out_shape,
-                    dtype=dt
-                ) + channel_defaults[i]
+                    dt = "uint8"
+                out_array[:, :, i] = (
+                    numpy.zeros(out_shape, dtype=dt) + channel_defaults[i]
+                )
             else:
                 # use a recurrent call to compute the channel and store it
                 # in the output
                 out_array[:, :, i] = tile_raster_images(
-                    X[i], img_shape, tile_shape, tile_spacing,
-                    scale_rows_to_unit_interval, output_pixel_vals)
+                    X[i],
+                    img_shape,
+                    tile_shape,
+                    tile_spacing,
+                    scale_rows_to_unit_interval,
+                    output_pixel_vals,
+                )
         return out_array
 
     else:
@@ -115,7 +126,7 @@
         # generate a matrix to store the output
         dt = X.dtype
         if output_pixel_vals:
-            dt = 'uint8'
+            dt = "uint8"
         out_array = numpy.zeros(out_shape, dtype=dt)
 
         for tile_row in range(tile_shape[0]):
@@ -127,7 +138,8 @@
                         # do this by calling the `scale_to_unit_interval`
                         # function
                         this_img = scale_to_unit_interval(
-                            this_x.reshape(img_shape))
+                            this_x.reshape(img_shape)
+                        )
                     else:
                         this_img = this_x.reshape(img_shape)
                     # add the slice to the corresponding position in the
@@ -136,7 +148,7 @@
                     if output_pixel_vals:
                         c = 255
                     out_array[
-                        tile_row * (H + Hs): tile_row * (H + Hs) + H,
-                        tile_col * (W + Ws): tile_col * (W + Ws) + W
-                    ] = this_img * c
+                        tile_row * (H + Hs) : tile_row * (H + Hs) + H,
+                        tile_col * (W + Ws) : tile_col * (W + Ws) + W,
+                    ] = (this_img * c)
         return out_array
diff --git a/examples/autograd/xceptionnet.py b/examples/autograd/xceptionnet.py
index f52a8ac..22070a9 100755
--- a/examples/autograd/xceptionnet.py
+++ b/examples/autograd/xceptionnet.py
@@ -1,3 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# =============================================================================
+
 from singa import autograd
 from singa import tensor
 from singa import device
diff --git a/examples/imagenet/inception/convert.py b/examples/imagenet/inception/convert.py
index 6406b70..973debd 100644
--- a/examples/imagenet/inception/convert.py
+++ b/examples/imagenet/inception/convert.py
@@ -1,17 +1,3 @@
-# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# ==============================================================================
 """Converting tensorflow checkpoint file to key-val pkl file."""
 from __future__ import absolute_import
 from __future__ import division
@@ -29,74 +15,80 @@
 
 try:
     import cPickle as pickle
-except ModuleNotFoundError:
+except ImportError:
     import pickle
 
 FLAGS = None
 
 
 def rename(name, suffix):
-    p = name.rfind('/')
+    p = name.rfind("/")
     if p == -1:
-        print('Bad name=%s' % name)
-    return name[0:p+1] + suffix
+        print("Bad name=%s" % name)
+    return name[0 : p + 1] + suffix
 
 
 def convert(model, file_name):
-    if model == 'v3':
+    if model == "v3":
         net, _ = inception_v3.create_net()
     else:
         net, _ = inception_v4.create_net()
-    params = {'SINGA_VERSION': 1101}
+    params = {"SINGA_VERSION": 1101}
     try:
         reader = pywrap_tensorflow.NewCheckpointReader(file_name)
         for pname, pval in zip(net.param_names(), net.param_values()):
-            if 'weight' in pname:
-                val = reader.get_tensor(rename(pname, 'weights'))
-                if 'Conv' in pname:
+            if "weight" in pname:
+                val = reader.get_tensor(rename(pname, "weights"))
+                if "Conv" in pname:
                     val = val.transpose((3, 2, 0, 1))
                     val = val.reshape((val.shape[0], -1))
-            elif 'bias' in pname:
-                val = reader.get_tensor(rename(pname, 'biases'))
-            elif 'mean' in pname:
-                val = reader.get_tensor(rename(pname, 'moving_mean'))
-            elif 'var' in pname:
-                val = reader.get_tensor(rename(pname, 'moving_variance'))
-            elif 'beta' in pname:
-                val= reader.get_tensor(pname)
-            elif 'gamma' in pname:
+            elif "bias" in pname:
+                val = reader.get_tensor(rename(pname, "biases"))
+            elif "mean" in pname:
+                val = reader.get_tensor(rename(pname, "moving_mean"))
+            elif "var" in pname:
+                val = reader.get_tensor(rename(pname, "moving_variance"))
+            elif "beta" in pname:
+                val = reader.get_tensor(pname)
+            elif "gamma" in pname:
                 val = np.ones(pval.shape)
             else:
-                print('not matched param %s' % pname)
-            assert val.shape == pval.shape, ('the shapes not match ',
-                    val.shape, pval.shape)
+                print("not matched param %s" % pname)
+            assert val.shape == pval.shape, (
+                "the shapes not match ",
+                val.shape,
+                pval.shape,
+            )
             params[pname] = val.astype(np.float32)
-            print('converting:', pname, pval.shape)
+            print("converting:", pname, pval.shape)
         var_to_shape_map = reader.get_variable_to_shape_map()
         for key in var_to_shape_map:
-            if 'weights' in key:
-                key = rename(key, 'weight')
-            elif 'biases' in key:
-                key = rename(key, 'bias')
-            elif 'moving_mean' in key:
-                key = rename(key, 'mean')
-            elif 'moving_variance' in key:
-                key = rename(key, 'var')
+            if "weights" in key:
+                key = rename(key, "weight")
+            elif "biases" in key:
+                key = rename(key, "bias")
+            elif "moving_mean" in key:
+                key = rename(key, "mean")
+            elif "moving_variance" in key:
+                key = rename(key, "var")
             if key not in params:
-                print('key=%s not in the net' % key)
-        '''
+                print("key=%s not in the net" % key)
+        """
         for key in var_to_shape_map:
             print("tensor_name: ", key, var_to_shape_map[key])
-        '''
-        with open(os.path.splitext(file_name)[0] + '.pickle', 'wb') as fd:
+        """
+        with open(os.path.splitext(file_name)[0] + ".pickle", "wb") as fd:
             pickle.dump(params, fd)
     except Exception as e:  # pylint: disable=broad-except
         print(str(e))
         if "corrupted compressed block contents" in str(e):
-            print("It's likely that your checkpoint file has been compressed "
-                    "with SNAPPY.")
-        if ("Data loss" in str(e) and
-            (any([e in file_name for e in [".index", ".meta", ".data"]]))):
+            print(
+                "It's likely that your checkpoint file has been compressed "
+                "with SNAPPY."
+            )
+        if "Data loss" in str(e) and (
+            any([e in file_name for e in [".index", ".meta", ".data"]])
+        ):
             proposed_file = ".".join(file_name.split(".")[0:-1])
             v2_file_error_template = """
     It's likely that this is a V2 checkpoint and you need to provide
@@ -105,7 +97,6 @@
         print(v2_file_error_template.format(proposed_file))
 
 
-
 def main(unused_argv):
     if not FLAGS.file_name:
         print("Usage: convert.py --file_name=checkpoint_file_name ")
@@ -117,7 +108,7 @@
 if __name__ == "__main__":
     parser = argparse.ArgumentParser()
     parser.register("type", "bool", lambda v: v.lower() == "true")
-    parser.add_argument("model", choices=['v3', 'v4'], help="inception version")
+    parser.add_argument("model", choices=["v3", "v4"], help="inception version")
     parser.add_argument("file_name", help="Checkpoint path")
     FLAGS, unparsed = parser.parse_known_args()
     app.run(main=main, argv=[sys.argv[0]] + unparsed)
diff --git a/include/singa/utils/mkldnn_utils.h b/include/singa/utils/mkldnn_utils.h
index ddee327..59bcf63 100644
--- a/include/singa/utils/mkldnn_utils.h
+++ b/include/singa/utils/mkldnn_utils.h
@@ -1,3 +1,23 @@
+/*********************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+************************************************************/
 #ifndef SINGA_UTILS_MKLDNN_UTILS_H_
 #define SINGA_UTILS_MKLDNN_UTILS_H_
 
diff --git a/include/singa/utils/stacktrace.h b/include/singa/utils/stacktrace.h
deleted file mode 100644
index 040071f..0000000
--- a/include/singa/utils/stacktrace.h
+++ /dev/null
@@ -1,42 +0,0 @@
-#include <execinfo.h>  // for backtrace
-#include <dlfcn.h>     // for dladdr
-#include <cxxabi.h>    // for __cxa_demangle
-
-#include <string>
-#include <sstream>
-
-// This function produces a stack backtrace with demangled function & method names.
-std::string Backtrace(int skip = 1)
-{
-	void *callstack[128];
-	const int nMaxFrames = sizeof(callstack) / sizeof(callstack[0]);
-	char buf[1024];
-	int nFrames = backtrace(callstack, nMaxFrames);
-	char **symbols = backtrace_symbols(callstack, nFrames);
-
-	std::ostringstream trace_buf;
-	for (int i = skip; i < nFrames; i++) {
-		Dl_info info;
-		if (dladdr(callstack[i], &info)) {
-			char *demangled = NULL;
-			int status;
-			demangled = abi::__cxa_demangle(info.dli_sname, NULL, 0, &status);
-			snprintf(buf, sizeof(buf), "%-3d %*0p %s + %zd\n",
-					 i, 2 + sizeof(void*) * 2, callstack[i],
-					 status == 0 ? demangled : info.dli_sname,
-					 (char *)callstack[i] - (char *)info.dli_saddr);
-			free(demangled);
-		} else {
-			snprintf(buf, sizeof(buf), "%-3d %*0p\n",
-					 i, 2 + sizeof(void*) * 2, callstack[i]);
-		}
-		trace_buf << buf;
-
-		snprintf(buf, sizeof(buf), "%s\n", symbols[i]);
-		trace_buf << buf;
-	}
-	free(symbols);
-	if (nFrames == nMaxFrames)
-		trace_buf << "[truncated]\n";
-	return trace_buf.str();
-}
\ No newline at end of file
diff --git a/rat-excludes b/rat-excludes
index 9dd92e6..0930056 100644
--- a/rat-excludes
+++ b/rat-excludes
@@ -1,13 +1 @@
-rat-excludes
-Doxyfile
-Makefile.*
-configure
-.gitignore
-doc/*
-config/*
-\.dirstamp
-config.*
-stamp-h1
-.*\.conf
-.*\.md
-control
+rat-excludes
\ No newline at end of file
diff --git a/src/api/config.i.in b/src/api/config.i.in
index 2312f2f..5bbfa1d 100644
--- a/src/api/config.i.in
+++ b/src/api/config.i.in
@@ -1,3 +1,22 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+
+
 // Pass in cmake configurations to swig
 #cmakedefine01 USE_CUDA
 #cmakedefine01 USE_CUDNN
diff --git a/src/api/model_operation.i b/src/api/model_operation.i
index b3b945c..02c957a 100755
--- a/src/api/model_operation.i
+++ b/src/api/model_operation.i
@@ -1,3 +1,24 @@
+/************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+
 %module model_operation
 
 %include "config.i"
diff --git a/src/core/tensor/tensor.cc b/src/core/tensor/tensor.cc
index 2495810..8c50437 100755
--- a/src/core/tensor/tensor.cc
+++ b/src/core/tensor/tensor.cc
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 #include "singa/core/tensor.h"
-#include "singa/utils/stacktrace.h"
+// #include "singa/utils/stacktrace.h"
 #include "./tensor_math.h"
 #include "./tensor_math_cpp.h"
 #include "./tensor_math_cuda.h"
@@ -345,8 +345,8 @@
   // transposed?
   auto m = shape_.size() - 1, n = shape.size() - 1;
   for (size_t i = 0; i <= std::min(m, n); i++) {
-    if ((shape.at(n-i) != shape_.at(m-i)) && (shape.at(n - i) != 1)) {
-      CHECK_EQ(shape_.at(m - i), 1) << "i= " << i << "\n" << Backtrace();
+    if ((shape.at(n - i) != shape_.at(m - i)) && (shape.at(n - i) != 1)) {
+      CHECK_EQ(shape_.at(m - i), 1) << "i= " << i << "\n"; // << Backtrace();
       shape_.at(m - i) = shape.at(n - i);
       stride_.at(m - i) = 0;
     }
diff --git a/src/model/operation/batchnorm.cc b/src/model/operation/batchnorm.cc
index f49dcd0..7a5a0f1 100755
--- a/src/model/operation/batchnorm.cc
+++ b/src/model/operation/batchnorm.cc
@@ -1,3 +1,23 @@
+/*********************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+************************************************************/
 #include "./batchnorm.h"
 
 namespace singa {
diff --git a/src/model/operation/batchnorm.h b/src/model/operation/batchnorm.h
index dff3afd..648614a 100755
--- a/src/model/operation/batchnorm.h
+++ b/src/model/operation/batchnorm.h
@@ -1,3 +1,23 @@
+/*********************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+************************************************************/
 //#ifndef SINGA_MODEL_OPERATION_BATCHNORM_H_
 //#define SINGA_MODEL_OPERATION_BATCHNORM_H_
 
diff --git a/src/model/operation/convolution.cc b/src/model/operation/convolution.cc
index 81a57b9..f2dc9a3 100755
--- a/src/model/operation/convolution.cc
+++ b/src/model/operation/convolution.cc
@@ -1,3 +1,23 @@
+/*********************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+************************************************************/
 #include "./convolution.h"
 #include "../layer/convolution.h"
 
diff --git a/src/model/operation/convolution.h b/src/model/operation/convolution.h
index 6547bdd..3148633 100755
--- a/src/model/operation/convolution.h
+++ b/src/model/operation/convolution.h
@@ -1,3 +1,23 @@
+/*********************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+************************************************************/
 #ifndef SINGA_MODEL_OPERATION_CONVOLUTION_H_
 #define SINGA_MODEL_OPERATION_CONVOLUTION_H_
 
diff --git a/src/model/operation/pooling.cc b/src/model/operation/pooling.cc
index f24a0d6..4878e49 100755
--- a/src/model/operation/pooling.cc
+++ b/src/model/operation/pooling.cc
@@ -1,3 +1,23 @@
+/*********************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+************************************************************/
 #include "./pooling.h"
 #include <cmath>
 
diff --git a/src/model/operation/pooling.h b/src/model/operation/pooling.h
index 4407fad..9154a5b 100644
--- a/src/model/operation/pooling.h
+++ b/src/model/operation/pooling.h
@@ -1,3 +1,23 @@
+/*********************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+************************************************************/
 #ifndef SINGA_MODEL_OPERATION_POOLING_H_
 #define SINGA_MODEL_OPERATION_POOLING_H_
 
diff --git a/test/python/test_mkldnn.py b/test/python/test_mkldnn.py
index 83390d5..3c2b115 100755
--- a/test/python/test_mkldnn.py
+++ b/test/python/test_mkldnn.py
@@ -1,3 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# =============================================================================
+
 import unittest
 from singa import singa_wrap
 
diff --git a/test/python/test_operation.py b/test/python/test_operation.py
index 3e11156..4d49287 100755
--- a/test/python/test_operation.py
+++ b/test/python/test_operation.py
@@ -1,3 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# =============================================================================
+
 import unittest
 from builtins import str