Unverified Commit b5a0d734 authored by Robert Kimball's avatar Robert Kimball Committed by GitHub

Update python wrapper to new Backend API (#863)

* remove obsolete

* change to use new Backend API

* rename parameter
parent ec501913
...@@ -106,3 +106,5 @@ python/share/* ...@@ -106,3 +106,5 @@ python/share/*
\#* \#*
\.#* \.#*
python/pybind11/
...@@ -17,21 +17,21 @@ ...@@ -17,21 +17,21 @@
import onnx import onnx
onnx_protobuf = onnx.load('/path/to/model/cntk_ResNet20_CIFAR10/model.onnx') onnx_protobuf = onnx.load('/path/to/model/cntk_ResNet20_CIFAR10/model.onnx')
# Convert a serialized ONNX model to an ngraph model # Convert a serialized ONNX model to an ngraph model
from ngraph_onnx.onnx_importer.importer import import_onnx_model from ngraph_onnx.onnx_importer.importer import import_onnx_model
ng_model = import_onnx_model(onnx_protobuf)[0] ng_model = import_onnx_model(onnx_protobuf)[0]
# Using an ngraph runtime (CPU backend), create a callable computation # Using an ngraph runtime (CPU backend), create a callable computation
import ngraph as ng import ngraph as ng
runtime = ng.runtime(manager_name='CPU') runtime = ng.runtime(backend_name='CPU')
resnet = runtime.computation(ng_model['output'], *ng_model['inputs']) resnet = runtime.computation(ng_model['output'], *ng_model['inputs'])
# Load or create an image # Load or create an image
import numpy as np import numpy as np
picture = np.ones([1, 3, 32, 32]) picture = np.ones([1, 3, 32, 32])
# Run ResNet inference on picture # Run ResNet inference on picture
resnet(picture) resnet(picture)
...@@ -29,7 +29,7 @@ model = (A + B) * C ...@@ -29,7 +29,7 @@ model = (A + B) * C
# >>> print(model) # >>> print(model)
# <Node: 'Multiply_6'> # <Node: 'Multiply_6'>
runtime = ng.runtime(manager_name='INTERPRETER') runtime = ng.runtime(backend_name='INTERPRETER')
# >>> print(runtime) # >>> print(runtime)
# <Runtime: Manager='INTERPRETER'> # <Runtime: Manager='INTERPRETER'>
......
...@@ -28,7 +28,4 @@ else: ...@@ -28,7 +28,4 @@ else:
sys.setdlopenflags(flags) sys.setdlopenflags(flags)
from _pyngraph.runtime import Backend from _pyngraph.runtime import Backend
from _pyngraph.runtime import CallFrame
from _pyngraph.runtime import ExternalFunction
from _pyngraph.runtime import Manager
from _pyngraph.runtime import TensorView from _pyngraph.runtime import TensorView
...@@ -20,7 +20,7 @@ from typing import List ...@@ -20,7 +20,7 @@ from typing import List
import numpy as np import numpy as np
from ngraph.impl import Function, Node, serialize, TensorViewType, util from ngraph.impl import Function, Node, serialize, TensorViewType, util
from ngraph.impl.runtime import Manager from ngraph.impl.runtime import Backend
from ngraph.impl.op import Parameter from ngraph.impl.op import Parameter
from ngraph.utils.types import get_dtype, NumericData from ngraph.utils.types import get_dtype, NumericData
...@@ -28,24 +28,23 @@ from ngraph.utils.types import get_dtype, NumericData ...@@ -28,24 +28,23 @@ from ngraph.utils.types import get_dtype, NumericData
log = logging.getLogger(__file__) log = logging.getLogger(__file__)
def runtime(manager_name='CPU'): # type: (str) -> 'Runtime' def runtime(backend_name='CPU'): # type: (str) -> 'Runtime'
"""Create a Runtime object (helper factory). """Create a Runtime object (helper factory).
Use signature to parametrize runtime as needed. Use signature to parameterize runtime as needed.
""" """
return Runtime(manager_name) return Runtime(backend_name)
class Runtime: class Runtime:
"""Represents the ngraph++ runtime environment.""" """Represents the ngraph++ runtime environment."""
def __init__(self, manager_name): # type: (str) -> None def __init__(self, backend_name): # type: (str) -> None
self.manager_name = manager_name self.backend_name = backend_name
self.manager = Manager.get(manager_name) self.backend = Backend.create(backend_name)
self.backend = self.manager.allocate_backend()
def __repr__(self): # type: () -> str def __repr__(self): # type: () -> str
return '<Runtime: Manager=\'{}\'>'.format(self.manager_name) return '<Runtime: Backend=\'{}\'>'.format(self.backend_name)
def computation(self, node, *inputs): # type: (Node, *Node) -> 'Computation' def computation(self, node, *inputs): # type: (Node, *Node) -> 'Computation'
"""Return a callable Computation object.""" """Return a callable Computation object."""
...@@ -63,10 +62,9 @@ class Computation: ...@@ -63,10 +62,9 @@ class Computation:
for parameter in parameters: for parameter in parameters:
shape = parameter.get_shape() shape = parameter.get_shape()
element_type = parameter.get_element_type() element_type = parameter.get_element_type()
self.tensor_views.append(runtime.backend.make_primary_tensor_view(element_type, shape)) self.tensor_views.append(runtime.backend.create_tensor(element_type, shape))
self.function = Function(self.node, self.parameters, 'ngraph_computation') self.function = Function(self.node, self.parameters, 'ngraph_computation')
external = self.runtime.manager.compile(self.function) self.backend = runtime.backend
self.call_frame = self.runtime.backend.make_call_frame(external)
def __repr__(self): # type: () -> str def __repr__(self): # type: () -> str
params_string = ', '.join([param.name for param in self.parameters]) params_string = ', '.join([param.name for param in self.parameters])
...@@ -83,11 +81,11 @@ class Computation: ...@@ -83,11 +81,11 @@ class Computation:
result_shape = self.node.get_shape() result_shape = self.node.get_shape()
result_dtype = get_dtype(result_element_type) result_dtype = get_dtype(result_element_type)
result_view = self.runtime.backend.make_primary_tensor_view( result_view = self.runtime.backend.create_tensor(
result_element_type, result_shape) result_element_type, result_shape)
result_arr = np.empty(result_shape, dtype=result_dtype) result_arr = np.empty(result_shape, dtype=result_dtype)
self.call_frame.call([result_view], self.tensor_views) self.backend.call(self.function, [result_view], self.tensor_views)
Computation._read_tensor_view_to_ndarray(result_view, result_arr) Computation._read_tensor_view_to_ndarray(result_view, result_arr)
result_arr = result_arr.reshape(result_shape) result_arr = result_arr.reshape(result_shape)
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
#include <pybind11/stl.h> #include <pybind11/stl.h>
//#include <string> //#include <string>
#include "ngraph/runtime/backend.hpp" #include "ngraph/runtime/backend.hpp"
#include "ngraph/runtime/backend.hpp"
#include "ngraph/runtime/external_function.hpp"
#include "ngraph/runtime/tensor_view.hpp" #include "ngraph/runtime/tensor_view.hpp"
#include "pyngraph/runtime/backend.hpp" #include "pyngraph/runtime/backend.hpp"
...@@ -30,9 +28,30 @@ void regclass_pyngraph_runtime_Backend(py::module m) ...@@ -30,9 +28,30 @@ void regclass_pyngraph_runtime_Backend(py::module m)
py::class_<ngraph::runtime::Backend, std::shared_ptr<ngraph::runtime::Backend>> backend( py::class_<ngraph::runtime::Backend, std::shared_ptr<ngraph::runtime::Backend>> backend(
m, "Backend"); m, "Backend");
backend.doc() = "ngraph.impl.runtime.Backend wraps ngraph::runtime::Backend"; backend.doc() = "ngraph.impl.runtime.Backend wraps ngraph::runtime::Backend";
backend.def("make_call_frame", &ngraph::runtime::Backend::make_call_frame); backend.def_static("create", &ngraph::runtime::Backend::create);
backend.def("make_primary_tensor_view", backend.def_static("get_registered_devices", &ngraph::runtime::Backend::get_registered_devices);
backend.def_static("get_subdevices", &ngraph::runtime::Backend::get_subdevices);
backend.def("create_tensor",
(std::shared_ptr<ngraph::runtime::TensorView>(ngraph::runtime::Backend::*)( (std::shared_ptr<ngraph::runtime::TensorView>(ngraph::runtime::Backend::*)(
const ngraph::element::Type&, const ngraph::Shape&)) & const ngraph::element::Type&, const ngraph::Shape&)) &
ngraph::runtime::Backend::create_tensor); ngraph::runtime::Backend::create_tensor);
backend.def("compile",
(void (ngraph::runtime::Backend::*)(std::shared_ptr<ngraph::Function>)) &
ngraph::runtime::Backend::compile);
backend.def("call",
(void (ngraph::runtime::Backend::*)(
std::shared_ptr<ngraph::Function>,
const std::vector<std::shared_ptr<ngraph::runtime::TensorView>>&,
const std::vector<std::shared_ptr<ngraph::runtime::TensorView>>&)) &
ngraph::runtime::Backend::call);
backend.def("remove_compiled_function",
(void (ngraph::runtime::Backend::*)(std::shared_ptr<ngraph::Function>)) &
ngraph::runtime::Backend::remove_compiled_function);
backend.def("enable_performance_data",
(void (ngraph::runtime::Backend::*)(std::shared_ptr<ngraph::Function>, bool)) &
ngraph::runtime::Backend::enable_performance_data);
backend.def("get_performance_data",
(std::vector<ngraph::runtime::PerformanceCounter>(ngraph::runtime::Backend::*)(
std::shared_ptr<ngraph::Function>)) &
ngraph::runtime::Backend::get_performance_data);
} }
/*******************************************************************************
* 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.
*******************************************************************************/
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
//#include <string>
#include "pyngraph/runtime/call_frame.hpp"
namespace py = pybind11;
void regclass_pyngraph_runtime_CallFrame(py::module m)
{
py::class_<ngraph::runtime::CallFrame, std::shared_ptr<ngraph::runtime::CallFrame>> callFrame(
m, "CallFrame");
callFrame.doc() = "ngraph.impl.runtime.CallFrame wraps ngraph::runtime::CallFrame";
callFrame.def("call", &ngraph::runtime::CallFrame::call);
}
/*******************************************************************************
* 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.
*******************************************************************************/
#pragma once
#include <pybind11/pybind11.h>
namespace py = pybind11;
void regclass_pyngraph_runtime_CallFrame(py::module m);
/*******************************************************************************
* 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.
*******************************************************************************/
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
//#include <string>
#include "ngraph/runtime/external_function.hpp"
#include "pyngraph/runtime/external_function.hpp"
namespace py = pybind11;
void regclass_pyngraph_runtime_ExternalFunction(py::module m)
{
py::class_<ngraph::runtime::ExternalFunction,
std::shared_ptr<ngraph::runtime::ExternalFunction>>
externalFunction(m, "ExternalFunction");
externalFunction.doc() =
"ngraph.impl.runtime.ExternalFunction wraps ngraph::runtime::ExternalFunction";
}
/*******************************************************************************
* 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.
*******************************************************************************/
#pragma once
#include <pybind11/pybind11.h>
namespace py = pybind11;
void regclass_pyngraph_runtime_ExternalFunction(py::module m);
/*******************************************************************************
* 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.
*******************************************************************************/
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
//#include <string>
#include "ngraph/function.hpp"
#include "ngraph/runtime/backend.hpp"
#include "ngraph/runtime/external_function.hpp"
#include "ngraph/runtime/manager.hpp"
#include "pyngraph/runtime/manager.hpp"
namespace py = pybind11;
void regclass_pyngraph_runtime_Manager(py::module m)
{
py::class_<ngraph::runtime::Manager, std::shared_ptr<ngraph::runtime::Manager>> manager(
m, "Manager");
manager.doc() = "ngraph.impl.runtime.Manager wraps ngraph::runtime::Manager";
manager.def_static("get", &ngraph::runtime::Manager::get);
manager.def("compile", &ngraph::runtime::Manager::compile);
manager.def("allocate_backend", &ngraph::runtime::Manager::allocate_backend);
}
/*******************************************************************************
* 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.
*******************************************************************************/
#pragma once
#include <pybind11/pybind11.h>
namespace py = pybind11;
void regclass_pyngraph_runtime_Manager(py::module m);
...@@ -25,7 +25,4 @@ void regmodule_pyngraph_runtime(py::module m) ...@@ -25,7 +25,4 @@ void regmodule_pyngraph_runtime(py::module m)
m.def_submodule("runtime", "Package ngraph.impl.runtime wraps ngraph::runtime"); m.def_submodule("runtime", "Package ngraph.impl.runtime wraps ngraph::runtime");
regclass_pyngraph_runtime_TensorView(m_runtime); regclass_pyngraph_runtime_TensorView(m_runtime);
regclass_pyngraph_runtime_Backend(m_runtime); regclass_pyngraph_runtime_Backend(m_runtime);
regclass_pyngraph_runtime_CallFrame(m_runtime);
regclass_pyngraph_runtime_ExternalFunction(m_runtime);
regclass_pyngraph_runtime_Manager(m_runtime);
} }
...@@ -18,9 +18,6 @@ ...@@ -18,9 +18,6 @@
#include <pybind11/pybind11.h> #include <pybind11/pybind11.h>
#include "pyngraph/runtime/backend.hpp" #include "pyngraph/runtime/backend.hpp"
#include "pyngraph/runtime/call_frame.hpp"
#include "pyngraph/runtime/external_function.hpp"
#include "pyngraph/runtime/manager.hpp"
#include "pyngraph/runtime/tensor_view.hpp" #include "pyngraph/runtime/tensor_view.hpp"
namespace py = pybind11; namespace py = pybind11;
......
...@@ -204,9 +204,6 @@ sources = ['pyngraph/function.cpp', ...@@ -204,9 +204,6 @@ sources = ['pyngraph/function.cpp',
'pyngraph/ops/batch_norm.cpp', 'pyngraph/ops/batch_norm.cpp',
'pyngraph/ops/softmax.cpp', 'pyngraph/ops/softmax.cpp',
'pyngraph/runtime/backend.cpp', 'pyngraph/runtime/backend.cpp',
'pyngraph/runtime/call_frame.cpp',
'pyngraph/runtime/external_function.cpp',
'pyngraph/runtime/manager.cpp',
'pyngraph/runtime/regmodule_pyngraph_runtime.cpp', 'pyngraph/runtime/regmodule_pyngraph_runtime.cpp',
'pyngraph/runtime/tensor_view.cpp', 'pyngraph/runtime/tensor_view.cpp',
'pyngraph/passes/manager.cpp', 'pyngraph/passes/manager.cpp',
......
...@@ -71,14 +71,14 @@ def test_function_call(): ...@@ -71,14 +71,14 @@ def test_function_call():
def test_serialization(): def test_serialization():
dtype = np.float32 dtype = np.float32
manager_name = pytest.config.getoption('backend', default='CPU') backend_name = pytest.config.getoption('backend', default='CPU')
shape = [2, 2] shape = [2, 2]
parameter_a = ng.parameter(shape, dtype=dtype, name='A') parameter_a = ng.parameter(shape, dtype=dtype, name='A')
parameter_b = ng.parameter(shape, dtype=dtype, name='B') parameter_b = ng.parameter(shape, dtype=dtype, name='B')
parameter_c = ng.parameter(shape, dtype=dtype, name='C') parameter_c = ng.parameter(shape, dtype=dtype, name='C')
model = (parameter_a + parameter_b) * parameter_c model = (parameter_a + parameter_b) * parameter_c
runtime = ng.runtime(manager_name=manager_name) runtime = ng.runtime(backend_name=backend_name)
computation = runtime.computation(model, parameter_a, parameter_b, parameter_c) computation = runtime.computation(model, parameter_a, parameter_b, parameter_c)
serialized = computation.serialize(2) serialized = computation.serialize(2)
serial_json = json.loads(serialized) serial_json = json.loads(serialized)
......
...@@ -27,8 +27,8 @@ def _get_numpy_dtype(scalar): ...@@ -27,8 +27,8 @@ def _get_numpy_dtype(scalar):
def get_runtime(): def get_runtime():
"""Return runtime object.""" """Return runtime object."""
manager_name = pytest.config.getoption('backend', default='CPU') backend_name = pytest.config.getoption('backend', default='CPU')
return ng.runtime(manager_name=manager_name) return ng.runtime(backend_name=backend_name)
def run_op_node(input_data, op_fun, *args): def run_op_node(input_data, op_fun, *args):
......
...@@ -22,7 +22,7 @@ import numpy as np ...@@ -22,7 +22,7 @@ import numpy as np
from ngraph.impl import util from ngraph.impl import util
from ngraph.impl import Shape, Strides, CoordinateDiff, AxisSet, AxisVector, Coordinate from ngraph.impl import Shape, Strides, CoordinateDiff, AxisSet, AxisVector, Coordinate
from ngraph.impl import Type, Function, NodeVector from ngraph.impl import Type, Function, NodeVector
from ngraph.impl.runtime import Manager from ngraph.impl.runtime import Backend
from ngraph.impl.op import Acos, Asin, Atan, Cos, Sin, Tan from ngraph.impl.op import Acos, Asin, Atan, Cos, Sin, Tan
from ngraph.impl.op import Cosh, Sinh, Tanh, Sqrt, Sign from ngraph.impl.op import Cosh, Sinh, Tanh, Sqrt, Sign
from ngraph.impl.op import Power, Negative, Ceiling, Floor from ngraph.impl.op import Power, Negative, Ceiling, Floor
...@@ -36,16 +36,6 @@ from ngraph.impl.op import Reverse, MaxPool, ReplaceSlice, Slice ...@@ -36,16 +36,6 @@ from ngraph.impl.op import Reverse, MaxPool, ReplaceSlice, Slice
from ngraph.impl.op import Convolution, ConvolutionBackpropData, ConvolutionBackpropFilters from ngraph.impl.op import Convolution, ConvolutionBackpropData, ConvolutionBackpropFilters
def make_backend_call_frame(function):
manager = Manager.get(pytest.config.getoption('backend'))
external = manager.compile(function)
backend = manager.allocate_backend()
cf = backend.make_call_frame(external)
return backend, cf
def binary_op(op_str, a, b): def binary_op(op_str, a, b):
if op_str == '+': if op_str == '+':
...@@ -126,7 +116,7 @@ def binary_op_exec(op_str): ...@@ -126,7 +116,7 @@ def binary_op_exec(op_str):
B = Parameter(element_type, shape) B = Parameter(element_type, shape)
parameter_list = [A, B] parameter_list = [A, B]
function = Function(NodeVector([binary_op(op_str, A, B)]), parameter_list, 'test') function = Function(NodeVector([binary_op(op_str, A, B)]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, shape) a = backend.create_tensor(element_type, shape)
b = backend.create_tensor(element_type, shape) b = backend.create_tensor(element_type, shape)
...@@ -137,7 +127,7 @@ def binary_op_exec(op_str): ...@@ -137,7 +127,7 @@ def binary_op_exec(op_str):
result_arr = np.array([[0, 0], [0, 0]], dtype=np.float32) result_arr = np.array([[0, 0], [0, 0]], dtype=np.float32)
result.write(util.numpy_to_c(result_arr), 0, 16) result.write(util.numpy_to_c(result_arr), 0, 16)
cf.call([result], [a, b]) backend.call(function, [result], [a, b])
result.read(util.numpy_to_c(result_arr), 0, 16) result.read(util.numpy_to_c(result_arr), 0, 16)
a_arr = np.array([[1, 6], [7, 4]], dtype=np.float32) a_arr = np.array([[1, 6], [7, 4]], dtype=np.float32)
...@@ -155,7 +145,7 @@ def binary_op_comparison(op_str): ...@@ -155,7 +145,7 @@ def binary_op_comparison(op_str):
B = Parameter(element_type, shape) B = Parameter(element_type, shape)
parameter_list = [A, B] parameter_list = [A, B]
function = Function(NodeVector([binary_op(op_str, A, B)]), parameter_list, 'test') function = Function(NodeVector([binary_op(op_str, A, B)]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, shape) a = backend.create_tensor(element_type, shape)
b = backend.create_tensor(element_type, shape) b = backend.create_tensor(element_type, shape)
...@@ -166,7 +156,7 @@ def binary_op_comparison(op_str): ...@@ -166,7 +156,7 @@ def binary_op_comparison(op_str):
result_arr = np.array([[False, False], [False, False]], dtype=np.bool) result_arr = np.array([[False, False], [False, False]], dtype=np.bool)
result.write(util.numpy_to_c(result_arr), 0, 4) result.write(util.numpy_to_c(result_arr), 0, 4)
cf.call([result], [a, b]) backend.call(function, [result], [a, b])
result.read(util.numpy_to_c(result_arr), 0, 4) result.read(util.numpy_to_c(result_arr), 0, 4)
a_arr = np.array([[1, 5], [3, 2]], dtype=np.float32) a_arr = np.array([[1, 5], [3, 2]], dtype=np.float32)
...@@ -253,7 +243,7 @@ def test_add_with_mul(): ...@@ -253,7 +243,7 @@ def test_add_with_mul():
C = Parameter(element_type, shape) C = Parameter(element_type, shape)
parameter_list = [A, B, C] parameter_list = [A, B, C]
function = Function(NodeVector([Multiply(Add(A, B), C)]), parameter_list, 'test') function = Function(NodeVector([Multiply(Add(A, B), C)]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, shape) a = backend.create_tensor(element_type, shape)
b = backend.create_tensor(element_type, shape) b = backend.create_tensor(element_type, shape)
...@@ -266,7 +256,7 @@ def test_add_with_mul(): ...@@ -266,7 +256,7 @@ def test_add_with_mul():
result_arr = np.array([0, 0, 0, 0], dtype=np.float32) result_arr = np.array([0, 0, 0, 0], dtype=np.float32)
result.write(util.numpy_to_c(result_arr), 0, 16) result.write(util.numpy_to_c(result_arr), 0, 16)
cf.call([result], [a, b, c]) backend.call(function, [result], [a, b, c])
result.read(util.numpy_to_c(result_arr), 0, 16) result.read(util.numpy_to_c(result_arr), 0, 16)
a_arr = np.array([1, 2, 3, 4], dtype=np.float32) a_arr = np.array([1, 2, 3, 4], dtype=np.float32)
...@@ -365,7 +355,7 @@ def unary_op_exec(op_str, input_list): ...@@ -365,7 +355,7 @@ def unary_op_exec(op_str, input_list):
A = Parameter(element_type, shape) A = Parameter(element_type, shape)
parameter_list = [A] parameter_list = [A]
function = Function(NodeVector([unary_op(op_str, A)]), parameter_list, 'test') function = Function(NodeVector([unary_op(op_str, A)]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, shape) a = backend.create_tensor(element_type, shape)
result = backend.create_tensor(element_type, shape) result = backend.create_tensor(element_type, shape)
...@@ -374,7 +364,7 @@ def unary_op_exec(op_str, input_list): ...@@ -374,7 +364,7 @@ def unary_op_exec(op_str, input_list):
result_arr = np.zeros(shape_np, dtype=np.float32) result_arr = np.zeros(shape_np, dtype=np.float32)
result.write(util.numpy_to_c(result_arr), 0, 16) result.write(util.numpy_to_c(result_arr), 0, 16)
cf.call([result], [a]) backend.call(function, [result], [a])
result.read(util.numpy_to_c(result_arr), 0, 16) result.read(util.numpy_to_c(result_arr), 0, 16)
a_arr = np.array(input_list, dtype=np.float32) a_arr = np.array(input_list, dtype=np.float32)
...@@ -498,7 +488,7 @@ def test_not(): ...@@ -498,7 +488,7 @@ def test_not():
A = Parameter(element_type, shape) A = Parameter(element_type, shape)
parameter_list = [A] parameter_list = [A]
function = Function(NodeVector([Not(A)]), parameter_list, 'test') function = Function(NodeVector([Not(A)]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, shape) a = backend.create_tensor(element_type, shape)
result = backend.create_tensor(Type.boolean, shape) result = backend.create_tensor(Type.boolean, shape)
...@@ -507,7 +497,7 @@ def test_not(): ...@@ -507,7 +497,7 @@ def test_not():
result_arr = np.array([False, False], dtype=np.bool) result_arr = np.array([False, False], dtype=np.bool)
result.write(util.numpy_to_c(result_arr), 0, 2) result.write(util.numpy_to_c(result_arr), 0, 2)
cf.call([result], [a]) backend.call(function, [result], [a])
result.read(util.numpy_to_c(result_arr), 0, 2) result.read(util.numpy_to_c(result_arr), 0, 2)
a_arr = np.array([True, False], dtype=np.bool) a_arr = np.array([True, False], dtype=np.bool)
...@@ -523,7 +513,7 @@ def test_sum(): ...@@ -523,7 +513,7 @@ def test_sum():
A = Parameter(element_type, shape) A = Parameter(element_type, shape)
parameter_list = [A] parameter_list = [A]
function = Function(NodeVector([Sum(A, AxisSet({1}))]), parameter_list, 'test') function = Function(NodeVector([Sum(A, AxisSet({1}))]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, shape) a = backend.create_tensor(element_type, shape)
result = backend.create_tensor(element_type, Shape([1])) result = backend.create_tensor(element_type, Shape([1]))
...@@ -532,7 +522,7 @@ def test_sum(): ...@@ -532,7 +522,7 @@ def test_sum():
result_arr = np.array([0], dtype=np.float32) result_arr = np.array([0], dtype=np.float32)
result.write(util.numpy_to_c(result_arr), 0, 4) result.write(util.numpy_to_c(result_arr), 0, 4)
cf.call([result], [a]) backend.call(function, [result], [a])
result.read(util.numpy_to_c(result_arr), 0, 4) result.read(util.numpy_to_c(result_arr), 0, 4)
a_arr = np.array([1, 2, 3, 4], dtype=np.float32) a_arr = np.array([1, 2, 3, 4], dtype=np.float32)
...@@ -548,7 +538,7 @@ def test_reshape(): ...@@ -548,7 +538,7 @@ def test_reshape():
A = Parameter(element_type, shape) A = Parameter(element_type, shape)
parameter_list = [A] parameter_list = [A]
function = Function(NodeVector([Reshape(A, AxisVector([0, 1]), Shape([3, 2]))]), parameter_list, 'test') function = Function(NodeVector([Reshape(A, AxisVector([0, 1]), Shape([3, 2]))]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, shape) a = backend.create_tensor(element_type, shape)
result = backend.create_tensor(element_type, Shape([3, 2])) result = backend.create_tensor(element_type, Shape([3, 2]))
...@@ -557,7 +547,7 @@ def test_reshape(): ...@@ -557,7 +547,7 @@ def test_reshape():
result_arr = np.array([[0, 0], [0, 0], [0, 0]], dtype=np.float32) result_arr = np.array([[0, 0], [0, 0], [0, 0]], dtype=np.float32)
result.write(util.numpy_to_c(result_arr), 0, 24) result.write(util.numpy_to_c(result_arr), 0, 24)
cf.call([result], [a]) backend.call(function, [result], [a])
result.read(util.numpy_to_c(result_arr), 0, 24) result.read(util.numpy_to_c(result_arr), 0, 24)
a_arr = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32) a_arr = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32)
...@@ -574,7 +564,7 @@ def test_convert(): ...@@ -574,7 +564,7 @@ def test_convert():
parameter_list = [A] parameter_list = [A]
# f32 to boolean # f32 to boolean
function = Function(NodeVector([Convert(A, Type.boolean)]), parameter_list, 'test') function = Function(NodeVector([Convert(A, Type.boolean)]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, shape) a = backend.create_tensor(element_type, shape)
result = backend.create_tensor(Type.boolean, shape) result = backend.create_tensor(Type.boolean, shape)
...@@ -583,7 +573,7 @@ def test_convert(): ...@@ -583,7 +573,7 @@ def test_convert():
result_arr = np.array([False, False, False], dtype=np.bool) result_arr = np.array([False, False, False], dtype=np.bool)
result.write(util.numpy_to_c(result_arr), 0, 3) result.write(util.numpy_to_c(result_arr), 0, 3)
cf.call([result], [a]) backend.call(function, [result], [a])
result.read(util.numpy_to_c(result_arr), 0, 3) result.read(util.numpy_to_c(result_arr), 0, 3)
a_arr = np.array([1, 5, 3], dtype=np.float32) a_arr = np.array([1, 5, 3], dtype=np.float32)
...@@ -592,7 +582,7 @@ def test_convert(): ...@@ -592,7 +582,7 @@ def test_convert():
# f32 to i32 # f32 to i32
function = Function(NodeVector([Convert(A, Type.i32)]), parameter_list, 'test') function = Function(NodeVector([Convert(A, Type.i32)]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
result = backend.create_tensor(Type.i32, shape) result = backend.create_tensor(Type.i32, shape)
...@@ -600,7 +590,7 @@ def test_convert(): ...@@ -600,7 +590,7 @@ def test_convert():
result_arr = np.array([0, 0, 0], dtype=np.int32) result_arr = np.array([0, 0, 0], dtype=np.int32)
result.write(util.numpy_to_c(result_arr), 0, 12) result.write(util.numpy_to_c(result_arr), 0, 12)
cf.call([result], [a]) backend.call(function, [result], [a])
result.read(util.numpy_to_c(result_arr), 0, 12) result.read(util.numpy_to_c(result_arr), 0, 12)
a_arr = np.array([1.4, 5.4, 3.9], dtype=np.float32) a_arr = np.array([1.4, 5.4, 3.9], dtype=np.float32)
...@@ -615,7 +605,7 @@ def test_broadcast(): ...@@ -615,7 +605,7 @@ def test_broadcast():
A = Parameter(element_type, Shape([3])) A = Parameter(element_type, Shape([3]))
parameter_list = [A] parameter_list = [A]
function = Function(NodeVector([Broadcast(A, Shape([3, 3]), AxisSet({0}))]), parameter_list, 'test') function = Function(NodeVector([Broadcast(A, Shape([3, 3]), AxisSet({0}))]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, Shape([3])) a = backend.create_tensor(element_type, Shape([3]))
result = backend.create_tensor(element_type, Shape([3, 3])) result = backend.create_tensor(element_type, Shape([3, 3]))
...@@ -624,7 +614,7 @@ def test_broadcast(): ...@@ -624,7 +614,7 @@ def test_broadcast():
result_arr = np.zeros((3, 3), dtype=np.float32) result_arr = np.zeros((3, 3), dtype=np.float32)
result.write(util.numpy_to_c(result_arr), 0, 36) result.write(util.numpy_to_c(result_arr), 0, 36)
cf.call([result], [a]) backend.call(function, [result], [a])
result.read(util.numpy_to_c(result_arr), 0, 36) result.read(util.numpy_to_c(result_arr), 0, 36)
a_arr = np.array([[0], [0], [0]], dtype=np.float32) a_arr = np.array([[0], [0], [0]], dtype=np.float32)
...@@ -640,13 +630,13 @@ def test_constant(): ...@@ -640,13 +630,13 @@ def test_constant():
parameter_list = [] parameter_list = []
function = Function(NodeVector([Constant(element_type, Shape([3, 3]), list(range(9)))]), function = Function(NodeVector([Constant(element_type, Shape([3, 3]), list(range(9)))]),
parameter_list, 'test') parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
result = backend.create_tensor(element_type, Shape([3, 3])) result = backend.create_tensor(element_type, Shape([3, 3]))
result_arr = np.zeros((3, 3), dtype=np.float32) result_arr = np.zeros((3, 3), dtype=np.float32)
result.write(util.numpy_to_c(result_arr), 0, 36) result.write(util.numpy_to_c(result_arr), 0, 36)
cf.call([result], []) backend.call(function, [result], [])
result.read(util.numpy_to_c(result_arr), 0, 36) result.read(util.numpy_to_c(result_arr), 0, 36)
result_arr_ref = np.arange(9).reshape(3, 3) result_arr_ref = np.arange(9).reshape(3, 3)
...@@ -670,7 +660,7 @@ def test_reduce(): ...@@ -670,7 +660,7 @@ def test_reduce():
function = Function(NodeVector([Reduce(A, constant_op, reduce_function, AxisSet({0}))]), function = Function(NodeVector([Reduce(A, constant_op, reduce_function, AxisSet({0}))]),
parameter_list, 'test') parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(float_element_type, Shape([2, 2, 2])) a = backend.create_tensor(float_element_type, Shape([2, 2, 2]))
result = backend.create_tensor(float_element_type, Shape([2, 2])) result = backend.create_tensor(float_element_type, Shape([2, 2]))
...@@ -679,7 +669,7 @@ def test_reduce(): ...@@ -679,7 +669,7 @@ def test_reduce():
result_arr = np.zeros((2, 2), dtype=np.float32) result_arr = np.zeros((2, 2), dtype=np.float32)
result.write(util.numpy_to_c(result_arr), 0, 16) result.write(util.numpy_to_c(result_arr), 0, 16)
cf.call([result], [a]) backend.call(function, [result], [a])
result.read(util.numpy_to_c(result_arr), 0, 16) result.read(util.numpy_to_c(result_arr), 0, 16)
a_arr = np.arange(8).reshape(2, 2, 2) a_arr = np.arange(8).reshape(2, 2, 2)
...@@ -694,7 +684,7 @@ def test_onehot(): ...@@ -694,7 +684,7 @@ def test_onehot():
A = Parameter(element_type, Shape([3])) A = Parameter(element_type, Shape([3]))
parameter_list = [A] parameter_list = [A]
function = Function(NodeVector([OneHot(A, Shape([3, 3]), 0)]), parameter_list, 'test') function = Function(NodeVector([OneHot(A, Shape([3, 3]), 0)]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, Shape([3])) a = backend.create_tensor(element_type, Shape([3]))
result = backend.create_tensor(element_type, Shape([3, 3])) result = backend.create_tensor(element_type, Shape([3, 3]))
...@@ -703,7 +693,7 @@ def test_onehot(): ...@@ -703,7 +693,7 @@ def test_onehot():
result_arr = np.zeros((3, 3), dtype=np.float32) result_arr = np.zeros((3, 3), dtype=np.float32)
result.write(util.numpy_to_c(result_arr), 0, 36) result.write(util.numpy_to_c(result_arr), 0, 36)
cf.call([result], [a]) backend.call(function, [result], [a])
result.read(util.numpy_to_c(result_arr), 0, 36) result.read(util.numpy_to_c(result_arr), 0, 36)
a_arr = np.array([1, 0, 2]) a_arr = np.array([1, 0, 2])
...@@ -722,7 +712,7 @@ def test_concat(): ...@@ -722,7 +712,7 @@ def test_concat():
parameter_list = [A, B, C] parameter_list = [A, B, C]
axis = 0 axis = 0
function = Function(NodeVector([Concat(NodeVector([A, B, C]), axis)]), parameter_list, 'test') function = Function(NodeVector([Concat(NodeVector([A, B, C]), axis)]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, Shape([1, 2])) a = backend.create_tensor(element_type, Shape([1, 2]))
b = backend.create_tensor(element_type, Shape([1, 2])) b = backend.create_tensor(element_type, Shape([1, 2]))
...@@ -735,7 +725,7 @@ def test_concat(): ...@@ -735,7 +725,7 @@ def test_concat():
result_arr = np.zeros(6, dtype=np.float32).reshape(3, 2) result_arr = np.zeros(6, dtype=np.float32).reshape(3, 2)
result.write(util.numpy_to_c(result_arr), 0, 24) result.write(util.numpy_to_c(result_arr), 0, 24)
cf.call([result], [a, b, c]) backend.call(function, [result], [a, b, c])
result.read(util.numpy_to_c(result_arr), 0, 24) result.read(util.numpy_to_c(result_arr), 0, 24)
a_arr = np.array([[1, 2]], dtype=np.float32) a_arr = np.array([[1, 2]], dtype=np.float32)
...@@ -756,7 +746,7 @@ def test_select(): ...@@ -756,7 +746,7 @@ def test_select():
parameter_list = [A, B, C] parameter_list = [A, B, C]
function = Function(NodeVector([Select(A, B, C)]), parameter_list, 'test') function = Function(NodeVector([Select(A, B, C)]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(Type.boolean, Shape([1, 2])) a = backend.create_tensor(Type.boolean, Shape([1, 2]))
b = backend.create_tensor(element_type, Shape([1, 2])) b = backend.create_tensor(element_type, Shape([1, 2]))
...@@ -769,7 +759,7 @@ def test_select(): ...@@ -769,7 +759,7 @@ def test_select():
result_arr = np.array([[0, 0]], dtype=np.float32) result_arr = np.array([[0, 0]], dtype=np.float32)
result.write(util.numpy_to_c(result_arr), 0, 8) result.write(util.numpy_to_c(result_arr), 0, 8)
cf.call([result], [a, b, c]) backend.call(function, [result], [a, b, c])
result.read(util.numpy_to_c(result_arr), 0, 8) result.read(util.numpy_to_c(result_arr), 0, 8)
result_arr_ref = np.array([[5, 8]]) result_arr_ref = np.array([[5, 8]])
...@@ -791,7 +781,7 @@ def test_slice(): ...@@ -791,7 +781,7 @@ def test_slice():
function = Function(NodeVector([Slice(A, Coordinate(lower_bounds), function = Function(NodeVector([Slice(A, Coordinate(lower_bounds),
Coordinate(upper_bounds))]), parameter_list, 'test') Coordinate(upper_bounds))]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, shape) a = backend.create_tensor(element_type, shape)
result = backend.create_tensor(element_type, Shape([4, 4])) result = backend.create_tensor(element_type, Shape([4, 4]))
...@@ -800,7 +790,7 @@ def test_slice(): ...@@ -800,7 +790,7 @@ def test_slice():
result_arr = np.zeros(16, dtype=np.float32).reshape(4, 4) result_arr = np.zeros(16, dtype=np.float32).reshape(4, 4)
result.write(util.numpy_to_c(result_arr), 0, 16*4) result.write(util.numpy_to_c(result_arr), 0, 16*4)
cf.call([result], [a]) backend.call(function, [result], [a])
result.read(util.numpy_to_c(result_arr), 0, 64) result.read(util.numpy_to_c(result_arr), 0, 64)
result_arr_ref = input_arr[lower_bounds[0]:upper_bounds[0], lower_bounds[1]:upper_bounds[1]] result_arr_ref = input_arr[lower_bounds[0]:upper_bounds[0], lower_bounds[1]:upper_bounds[1]]
...@@ -813,13 +803,13 @@ def test_slice(): ...@@ -813,13 +803,13 @@ def test_slice():
function = Function(NodeVector([Slice(A, Coordinate(lower_bounds), Coordinate(upper_bounds), function = Function(NodeVector([Slice(A, Coordinate(lower_bounds), Coordinate(upper_bounds),
Strides(strides))]), parameter_list, 'test') Strides(strides))]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
result = backend.create_tensor(element_type, Shape([4, 2])) result = backend.create_tensor(element_type, Shape([4, 2]))
result_arr = np.zeros(8, dtype=np.float32).reshape(4, 2) result_arr = np.zeros(8, dtype=np.float32).reshape(4, 2)
result.write(util.numpy_to_c(result_arr), 0, 8*4) result.write(util.numpy_to_c(result_arr), 0, 8*4)
cf.call([result], [a]) backend.call(function, [result], [a])
result.read(util.numpy_to_c(result_arr), 0, 32) result.read(util.numpy_to_c(result_arr), 0, 32)
result_arr_ref = result_arr_ref[::strides[0], ::strides[1]] result_arr_ref = result_arr_ref[::strides[0], ::strides[1]]
...@@ -842,7 +832,7 @@ def test_replace_slice(): ...@@ -842,7 +832,7 @@ def test_replace_slice():
function = Function(NodeVector([ReplaceSlice(A, B, Coordinate(lower_bounds), function = Function(NodeVector([ReplaceSlice(A, B, Coordinate(lower_bounds),
Coordinate(upper_bounds))]), parameter_list, 'test') Coordinate(upper_bounds))]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, Shape([6, 4])) a = backend.create_tensor(element_type, Shape([6, 4]))
b = backend.create_tensor(element_type, Shape([3, 2])) b = backend.create_tensor(element_type, Shape([3, 2]))
...@@ -853,7 +843,7 @@ def test_replace_slice(): ...@@ -853,7 +843,7 @@ def test_replace_slice():
result_arr = np.zeros(24, dtype=np.float32).reshape(6, 4) result_arr = np.zeros(24, dtype=np.float32).reshape(6, 4)
result.write(util.numpy_to_c(result_arr), 0, 24*4) result.write(util.numpy_to_c(result_arr), 0, 24*4)
cf.call([result], [a, b]) backend.call(function, [result], [a, b])
result.read(util.numpy_to_c(result_arr), 0, 24*4) result.read(util.numpy_to_c(result_arr), 0, 24*4)
result_arr_ref = np.copy(input_arr_a) result_arr_ref = np.copy(input_arr_a)
...@@ -869,9 +859,9 @@ def test_replace_slice(): ...@@ -869,9 +859,9 @@ def test_replace_slice():
function = Function(NodeVector([ReplaceSlice(A, B, Coordinate(lower_bounds), function = Function(NodeVector([ReplaceSlice(A, B, Coordinate(lower_bounds),
Coordinate(upper_bounds), Strides(strides))]), Coordinate(upper_bounds), Strides(strides))]),
parameter_list, 'test') parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
cf.call([result], [a, b]) backend.call(function, [result], [a, b])
result.read(util.numpy_to_c(result_arr), 0, 24*4) result.read(util.numpy_to_c(result_arr), 0, 24*4)
result_arr_ref = np.copy(input_arr_a) result_arr_ref = np.copy(input_arr_a)
...@@ -893,7 +883,7 @@ def test_max_pool(): ...@@ -893,7 +883,7 @@ def test_max_pool():
window_shape = [3] window_shape = [3]
function = Function(NodeVector([MaxPool(A, Shape(window_shape))]), parameter_list, 'test') function = Function(NodeVector([MaxPool(A, Shape(window_shape))]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, shape) a = backend.create_tensor(element_type, shape)
result = backend.create_tensor(element_type, Shape([1, 1, 8])) result = backend.create_tensor(element_type, Shape([1, 1, 8]))
...@@ -902,7 +892,7 @@ def test_max_pool(): ...@@ -902,7 +892,7 @@ def test_max_pool():
result_arr = np.zeros(8, dtype=np.float32).reshape(1, 1, 8) result_arr = np.zeros(8, dtype=np.float32).reshape(1, 1, 8)
result.write(util.numpy_to_c(result_arr), 0, 8*4) result.write(util.numpy_to_c(result_arr), 0, 8*4)
cf.call([result], [a]) backend.call(function, [result], [a])
result.read(util.numpy_to_c(result_arr), 0, 32) result.read(util.numpy_to_c(result_arr), 0, 32)
result_arr_ref = (np.arange(8) + 2).reshape(1, 1, 8) result_arr_ref = (np.arange(8) + 2).reshape(1, 1, 8)
...@@ -912,14 +902,14 @@ def test_max_pool(): ...@@ -912,14 +902,14 @@ def test_max_pool():
strides = [2] strides = [2]
function = Function(NodeVector([MaxPool(A, Shape(window_shape), Strides(strides))]), parameter_list, 'test') function = Function(NodeVector([MaxPool(A, Shape(window_shape), Strides(strides))]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
size = 4 size = 4
result = backend.create_tensor(element_type, Shape([1, 1, size])) result = backend.create_tensor(element_type, Shape([1, 1, size]))
result_arr = np.zeros(size, dtype=np.float32).reshape(1, 1, size) result_arr = np.zeros(size, dtype=np.float32).reshape(1, 1, size)
result.write(util.numpy_to_c(result_arr), 0, size*4) result.write(util.numpy_to_c(result_arr), 0, size*4)
cf.call([result], [a]) backend.call(function, [result], [a])
result.read(util.numpy_to_c(result_arr), 0, size*4) result.read(util.numpy_to_c(result_arr), 0, size*4)
result_arr_ref = ((np.arange(size) + 1) * 2).reshape(1, 1, size) result_arr_ref = ((np.arange(size) + 1) * 2).reshape(1, 1, size)
...@@ -935,7 +925,7 @@ def test_max_pool(): ...@@ -935,7 +925,7 @@ def test_max_pool():
window_shape = [3, 3] window_shape = [3, 3]
function = Function(NodeVector([MaxPool(A, Shape(window_shape))]), parameter_list, 'test') function = Function(NodeVector([MaxPool(A, Shape(window_shape))]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, shape) a = backend.create_tensor(element_type, shape)
result = backend.create_tensor(element_type, Shape([1, 1, 8, 8])) result = backend.create_tensor(element_type, Shape([1, 1, 8, 8]))
...@@ -944,7 +934,7 @@ def test_max_pool(): ...@@ -944,7 +934,7 @@ def test_max_pool():
result_arr = np.zeros(64, dtype=np.float32).reshape(1, 1, 8, 8) result_arr = np.zeros(64, dtype=np.float32).reshape(1, 1, 8, 8)
result.write(util.numpy_to_c(result_arr), 0, 8*8*4) result.write(util.numpy_to_c(result_arr), 0, 8*8*4)
cf.call([result], [a]) backend.call(function, [result], [a])
result.read(util.numpy_to_c(result_arr), 0, 8*8*4) result.read(util.numpy_to_c(result_arr), 0, 8*8*4)
result_arr_ref = ((np.arange(100).reshape(10, 10))[2:, 2:]).reshape(1, 1, 8, 8) result_arr_ref = ((np.arange(100).reshape(10, 10))[2:, 2:]).reshape(1, 1, 8, 8)
...@@ -954,14 +944,14 @@ def test_max_pool(): ...@@ -954,14 +944,14 @@ def test_max_pool():
strides = [2, 2] strides = [2, 2]
function = Function(NodeVector([MaxPool(A, Shape(window_shape), Strides(strides))]), parameter_list, 'test') function = Function(NodeVector([MaxPool(A, Shape(window_shape), Strides(strides))]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
size = 4 size = 4
result = backend.create_tensor(element_type, Shape([1, 1, size, size])) result = backend.create_tensor(element_type, Shape([1, 1, size, size]))
result_arr = np.zeros(size*size, dtype=np.float32).reshape(1, 1, size, size) result_arr = np.zeros(size*size, dtype=np.float32).reshape(1, 1, size, size)
result.write(util.numpy_to_c(result_arr), 0, size*size*4) result.write(util.numpy_to_c(result_arr), 0, size*size*4)
cf.call([result], [a]) backend.call(function, [result], [a])
result.read(util.numpy_to_c(result_arr), 0, size*size*4) result.read(util.numpy_to_c(result_arr), 0, size*size*4)
result_arr_ref = ((np.arange(100).reshape(10, 10))[2::2, 2::2]).reshape(1, 1, size, size) result_arr_ref = ((np.arange(100).reshape(10, 10))[2::2, 2::2]).reshape(1, 1, size, size)
...@@ -1031,7 +1021,7 @@ def test_convolution(): ...@@ -1031,7 +1021,7 @@ def test_convolution():
result_arr = np.zeros(196, dtype=np.float32).reshape(1, 1, 14, 14) result_arr = np.zeros(196, dtype=np.float32).reshape(1, 1, 14, 14)
function = Function(NodeVector([Convolution(A, B)]), parameter_list, 'test') function = Function(NodeVector([Convolution(A, B)]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, image_shape) a = backend.create_tensor(element_type, image_shape)
b = backend.create_tensor(element_type, filter_shape) b = backend.create_tensor(element_type, filter_shape)
...@@ -1041,7 +1031,7 @@ def test_convolution(): ...@@ -1041,7 +1031,7 @@ def test_convolution():
result = backend.create_tensor(element_type, Shape([1, 1, 14, 14])) result = backend.create_tensor(element_type, Shape([1, 1, 14, 14]))
result.write(util.numpy_to_c(result_arr), 0, 14*14*4) result.write(util.numpy_to_c(result_arr), 0, 14*14*4)
cf.call([result], [a, b]) backend.call(function, [result], [a, b])
result.read(util.numpy_to_c(result_arr), 0, 14*14*4) result.read(util.numpy_to_c(result_arr), 0, 14*14*4)
result_arr_ref = convolution2d(image_arr[0][0], filter_arr[0][0]).reshape(1, 1, 14, 14) result_arr_ref = convolution2d(image_arr[0][0], filter_arr[0][0]).reshape(1, 1, 14, 14)
...@@ -1064,7 +1054,7 @@ def test_convolution_with_strides(): ...@@ -1064,7 +1054,7 @@ def test_convolution_with_strides():
strides = [2, 2] strides = [2, 2]
function = Function(NodeVector([Convolution(A, B, Strides(strides))]), parameter_list, 'test') function = Function(NodeVector([Convolution(A, B, Strides(strides))]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, image_shape) a = backend.create_tensor(element_type, image_shape)
b = backend.create_tensor(element_type, filter_shape) b = backend.create_tensor(element_type, filter_shape)
...@@ -1075,7 +1065,7 @@ def test_convolution_with_strides(): ...@@ -1075,7 +1065,7 @@ def test_convolution_with_strides():
result_arr = np.zeros(16, dtype=np.float32).reshape(1, 1, 4, 4) result_arr = np.zeros(16, dtype=np.float32).reshape(1, 1, 4, 4)
result = backend.create_tensor(element_type, Shape([1, 1, 4, 4])) result = backend.create_tensor(element_type, Shape([1, 1, 4, 4]))
result.write(util.numpy_to_c(result_arr), 0, 4*4*4) result.write(util.numpy_to_c(result_arr), 0, 4*4*4)
cf.call([result], [a, b]) backend.call(function, [result], [a, b])
result.read(util.numpy_to_c(result_arr), 0, 4*4*4) result.read(util.numpy_to_c(result_arr), 0, 4*4*4)
result_arr_ref = convolution2d(image_arr[0][0], filter_arr[0][0], strides).reshape(1, 1, 4, 4) result_arr_ref = convolution2d(image_arr[0][0], filter_arr[0][0], strides).reshape(1, 1, 4, 4)
...@@ -1098,7 +1088,7 @@ def test_convolution_with_filter_dilation(): ...@@ -1098,7 +1088,7 @@ def test_convolution_with_filter_dilation():
dilation = [2, 2] dilation = [2, 2]
function = Function(NodeVector([Convolution(A, B, Strides(strides), Strides(dilation))]), parameter_list, 'test') function = Function(NodeVector([Convolution(A, B, Strides(strides), Strides(dilation))]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, image_shape) a = backend.create_tensor(element_type, image_shape)
b = backend.create_tensor(element_type, filter_shape) b = backend.create_tensor(element_type, filter_shape)
...@@ -1109,7 +1099,7 @@ def test_convolution_with_filter_dilation(): ...@@ -1109,7 +1099,7 @@ def test_convolution_with_filter_dilation():
result_arr = np.zeros(36, dtype=np.float32).reshape(1, 1, 6, 6) result_arr = np.zeros(36, dtype=np.float32).reshape(1, 1, 6, 6)
result = backend.create_tensor(element_type, Shape([1, 1, 6, 6])) result = backend.create_tensor(element_type, Shape([1, 1, 6, 6]))
result.write(util.numpy_to_c(result_arr), 0, 6*6*4) result.write(util.numpy_to_c(result_arr), 0, 6*6*4)
cf.call([result], [a, b]) backend.call(function, [result], [a, b])
result.read(util.numpy_to_c(result_arr), 0, 6*6*4) result.read(util.numpy_to_c(result_arr), 0, 6*6*4)
result_arr_ref = convolution2d(image_arr[0][0], filter_arr[0][0], strides, result_arr_ref = convolution2d(image_arr[0][0], filter_arr[0][0], strides,
...@@ -1138,7 +1128,7 @@ def test_convolution_with_padding(): ...@@ -1138,7 +1128,7 @@ def test_convolution_with_padding():
function = Function(NodeVector([Convolution(A, B, Strides(strides), Strides(dilation), function = Function(NodeVector([Convolution(A, B, Strides(strides), Strides(dilation),
CoordinateDiff(padding_below), CoordinateDiff(padding_above))]), CoordinateDiff(padding_below), CoordinateDiff(padding_above))]),
parameter_list, 'test') parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, image_shape) a = backend.create_tensor(element_type, image_shape)
b = backend.create_tensor(element_type, filter_shape) b = backend.create_tensor(element_type, filter_shape)
...@@ -1149,7 +1139,7 @@ def test_convolution_with_padding(): ...@@ -1149,7 +1139,7 @@ def test_convolution_with_padding():
result_arr = np.zeros(36, dtype=np.float32).reshape(1, 1, 6, 6) result_arr = np.zeros(36, dtype=np.float32).reshape(1, 1, 6, 6)
result = backend.create_tensor(element_type, Shape([1, 1, 6, 6])) result = backend.create_tensor(element_type, Shape([1, 1, 6, 6]))
result.write(util.numpy_to_c(result_arr), 0, 6*6*4) result.write(util.numpy_to_c(result_arr), 0, 6*6*4)
cf.call([result], [a, b]) backend.call(function, [result], [a, b])
result.read(util.numpy_to_c(result_arr), 0, 6*6*4) result.read(util.numpy_to_c(result_arr), 0, 6*6*4)
result_arr_ref = convolution2d(image_arr[0][0], filter_arr[0][0], strides, result_arr_ref = convolution2d(image_arr[0][0], filter_arr[0][0], strides,
...@@ -1176,7 +1166,7 @@ def test_convolution_with_padding(): ...@@ -1176,7 +1166,7 @@ def test_convolution_with_padding():
function = Function(NodeVector([Convolution(A, B, Strides(strides), Strides(dilation), function = Function(NodeVector([Convolution(A, B, Strides(strides), Strides(dilation),
CoordinateDiff(padding_below), CoordinateDiff(padding_above))]), CoordinateDiff(padding_below), CoordinateDiff(padding_above))]),
parameter_list, 'test') parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, image_shape) a = backend.create_tensor(element_type, image_shape)
b = backend.create_tensor(element_type, filter_shape) b = backend.create_tensor(element_type, filter_shape)
...@@ -1187,7 +1177,7 @@ def test_convolution_with_padding(): ...@@ -1187,7 +1177,7 @@ def test_convolution_with_padding():
result_arr = np.zeros(81, dtype=np.float32).reshape(1, 1, 9, 9) result_arr = np.zeros(81, dtype=np.float32).reshape(1, 1, 9, 9)
result = backend.create_tensor(element_type, Shape([1, 1, 9, 9])) result = backend.create_tensor(element_type, Shape([1, 1, 9, 9]))
result.write(util.numpy_to_c(result_arr), 0, 9*9*4) result.write(util.numpy_to_c(result_arr), 0, 9*9*4)
cf.call([result], [a, b]) backend.call(function, [result], [a, b])
result.read(util.numpy_to_c(result_arr), 0, 9*9*4) result.read(util.numpy_to_c(result_arr), 0, 9*9*4)
result_arr_ref = convolution2d(image_arr[0][0], filter_arr[0][0], strides, result_arr_ref = convolution2d(image_arr[0][0], filter_arr[0][0], strides,
...@@ -1217,7 +1207,7 @@ def test_convolution_with_data_dilation(): ...@@ -1217,7 +1207,7 @@ def test_convolution_with_data_dilation():
function = Function(NodeVector([Convolution(A, B, Strides(strides), Strides(dilation), function = Function(NodeVector([Convolution(A, B, Strides(strides), Strides(dilation),
CoordinateDiff(padding_below), CoordinateDiff(padding_above), CoordinateDiff(padding_below), CoordinateDiff(padding_above),
Strides(data_dilation))]), parameter_list, 'test') Strides(data_dilation))]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, image_shape) a = backend.create_tensor(element_type, image_shape)
b = backend.create_tensor(element_type, filter_shape) b = backend.create_tensor(element_type, filter_shape)
...@@ -1228,7 +1218,7 @@ def test_convolution_with_data_dilation(): ...@@ -1228,7 +1218,7 @@ def test_convolution_with_data_dilation():
result_arr = np.zeros(17*17, dtype=np.float32).reshape(1, 1, 17, 17) result_arr = np.zeros(17*17, dtype=np.float32).reshape(1, 1, 17, 17)
result = backend.create_tensor(element_type, Shape([1, 1, 17, 17])) result = backend.create_tensor(element_type, Shape([1, 1, 17, 17]))
result.write(util.numpy_to_c(result_arr), 0, 17*17*4) result.write(util.numpy_to_c(result_arr), 0, 17*17*4)
cf.call([result], [a, b]) backend.call(function, [result], [a, b])
result.read(util.numpy_to_c(result_arr), 0, 17*17*4) result.read(util.numpy_to_c(result_arr), 0, 17*17*4)
result_arr_ref = convolution2d(image_arr[0][0], filter_arr[0][0], strides, result_arr_ref = convolution2d(image_arr[0][0], filter_arr[0][0], strides,
...@@ -1264,7 +1254,7 @@ def test_convolutionBackpropData(): ...@@ -1264,7 +1254,7 @@ def test_convolutionBackpropData():
function = Function(NodeVector([ConvolutionBackpropData(image_shape, A, B, Strides(window_strides), Strides(window_dilation), function = Function(NodeVector([ConvolutionBackpropData(image_shape, A, B, Strides(window_strides), Strides(window_dilation),
CoordinateDiff(padding_below), CoordinateDiff(padding_above), CoordinateDiff(padding_below), CoordinateDiff(padding_above),
Strides(data_dilation))]), parameter_list, 'test') Strides(data_dilation))]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, filter_shape) a = backend.create_tensor(element_type, filter_shape)
b = backend.create_tensor(element_type, output_shape) b = backend.create_tensor(element_type, output_shape)
...@@ -1275,7 +1265,7 @@ def test_convolutionBackpropData(): ...@@ -1275,7 +1265,7 @@ def test_convolutionBackpropData():
result_arr = np.zeros(10*10, dtype=np.float32).reshape(1, 1, 10, 10) result_arr = np.zeros(10*10, dtype=np.float32).reshape(1, 1, 10, 10)
result = backend.create_tensor(element_type, Shape([1, 1, 10, 10])) result = backend.create_tensor(element_type, Shape([1, 1, 10, 10]))
result.write(util.numpy_to_c(result_arr), 0, 10*10*4) result.write(util.numpy_to_c(result_arr), 0, 10*10*4)
cf.call([result], [a, b]) backend.call(function, [result], [a, b])
result.read(util.numpy_to_c(result_arr), 0, 10*10*4) result.read(util.numpy_to_c(result_arr), 0, 10*10*4)
result_arr_ref = np.array( result_arr_ref = np.array(
...@@ -1319,7 +1309,7 @@ def test_convolutionBackpropFilters(): ...@@ -1319,7 +1309,7 @@ def test_convolutionBackpropFilters():
function = Function(NodeVector([ConvolutionBackpropFilters(A, filter_shape, B, Strides(window_strides), Strides(window_dilation), function = Function(NodeVector([ConvolutionBackpropFilters(A, filter_shape, B, Strides(window_strides), Strides(window_dilation),
CoordinateDiff(padding_below),CoordinateDiff(padding_above), CoordinateDiff(padding_below),CoordinateDiff(padding_above),
Strides(data_dilation))]), parameter_list, 'test') Strides(data_dilation))]), parameter_list, 'test')
backend, cf = make_backend_call_frame(function) backend = Backend.create(pytest.config.getoption('backend'))
a = backend.create_tensor(element_type, image_shape) a = backend.create_tensor(element_type, image_shape)
b = backend.create_tensor(element_type, output_shape) b = backend.create_tensor(element_type, output_shape)
...@@ -1330,7 +1320,7 @@ def test_convolutionBackpropFilters(): ...@@ -1330,7 +1320,7 @@ def test_convolutionBackpropFilters():
result_arr = np.zeros(3*3, dtype=np.float32).reshape(1, 1, 3, 3) result_arr = np.zeros(3*3, dtype=np.float32).reshape(1, 1, 3, 3)
result = backend.create_tensor(element_type, Shape([1, 1, 3, 3])) result = backend.create_tensor(element_type, Shape([1, 1, 3, 3]))
result.write(util.numpy_to_c(result_arr), 0, 3*3*4) result.write(util.numpy_to_c(result_arr), 0, 3*3*4)
cf.call([result], [a, b]) backend.call(function, [result], [a, b])
result.read(util.numpy_to_c(result_arr), 0, 3*3*4) result.read(util.numpy_to_c(result_arr), 0, 3*3*4)
result_arr_ref = np.array( result_arr_ref = np.array(
......
...@@ -40,7 +40,7 @@ namespace ngraph ...@@ -40,7 +40,7 @@ namespace ngraph
/// ///
/// | Type | Description | /// | Type | Description |
/// | ------- | --------------------------------------------------------------------------------------------------------------------------- | /// | ------- | --------------------------------------------------------------------------------------------------------------------------- |
/// | \f$T\f$ | The value of the parameter, supplied by the `FunctionCall` to this function or in the initial `ngraph::runtime::CallFrame`. | /// | \f$T\f$ | The value of the parameter, supplied by the `FunctionCall` to this function. |
class Parameter : public op::Op class Parameter : public op::Op
{ {
protected: protected:
......
...@@ -25,7 +25,6 @@ namespace ngraph ...@@ -25,7 +25,6 @@ namespace ngraph
{ {
namespace runtime namespace runtime
{ {
class CallFrame;
namespace cpu namespace cpu
{ {
class CPU_ExternalFunction; class CPU_ExternalFunction;
......
...@@ -27,8 +27,6 @@ namespace ngraph ...@@ -27,8 +27,6 @@ namespace ngraph
{ {
namespace cpu namespace cpu
{ {
class CallFrame;
namespace eigen namespace eigen
{ {
using DynamicStrides = Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>; using DynamicStrides = Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment