Commit 21d4e6e3 authored by Adam Procter's avatar Adam Procter

De-Eigenize select

parent 6d336670
// ----------------------------------------------------------------------------
// Copyright 2017 Nervana Systems Inc.
// 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
// ----------------------------------------------------------------------------
#pragma once
namespace ngraph
{
namespace runtime
{
namespace kernel
{
template <typename T>
void select(char* arg0, T* arg1, T* arg2, T* out, size_t count) // FIXME: temporararily char not bool
{
for (size_t i = 0; i < count; i++)
{
out[i] = arg0[i] ? arg1[i] : arg2[i];
}
}
}
}
}
......@@ -115,7 +115,7 @@
#include "ngraph/runtime/ngvm/eigen/replace_vector_slice.hpp"
#include "ngraph/runtime/ngvm/eigen/return.hpp"
#include "ngraph/runtime/ngvm/eigen/scalar_tensor_product.hpp"
#include "ngraph/runtime/ngvm/eigen/select.hpp"
#include "ngraph/runtime/ngvm/instruction/select.hpp"
#include "ngraph/runtime/ngvm/instruction/sign.hpp"
#include "ngraph/runtime/ngvm/instruction/sin.hpp"
#include "ngraph/runtime/ngvm/instruction/sinh.hpp"
......@@ -399,7 +399,7 @@ ExternalFunction::OpMap& ExternalFunction::get_op_map()
REGISTER_POLYMORPHIC_BINOP(op::Less, instruction::LessInstruction);
REGISTER_POLYMORPHIC_BINOP(op::LessEq, instruction::LessEqInstruction);
REGISTER_POLYMORPHIC_TERNOP(op::Select, eigen::SelectInstruction);
REGISTER_POLYMORPHIC_TERNOP(op::Select, instruction::SelectInstruction);
REGISTER_CONSTANT_INSTRUCTIONS(element::Bool);
REGISTER_CONSTANT_INSTRUCTIONS(element::Float32);
......
......@@ -14,8 +14,9 @@
#pragma once
#include "ngraph/runtime/kernel/select.hpp"
#include "ngraph/runtime/ngvm/call_frame.hpp"
#include "ngraph/runtime/ngvm/eigen/utils.hpp"
#include "ngraph/runtime/ngvm/utils.hpp"
#include "ngraph/runtime/ngvm/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
......@@ -25,16 +26,16 @@ namespace ngraph
{
namespace ngvm
{
namespace eigen
namespace instruction
{
template <typename ET>
class SelectInstruction : public Instruction
{
public:
SelectInstruction(TensorViewInfo arg0,
TensorViewInfo arg1,
TensorViewInfo arg2,
TensorViewInfo out)
SelectInstruction(const TensorViewInfo& arg0,
const TensorViewInfo& arg1,
const TensorViewInfo& arg2,
const TensorViewInfo& out)
: m_arg0(arg0)
, m_arg1(arg1)
, m_arg2(arg2)
......@@ -44,10 +45,14 @@ namespace ngraph
virtual void execute(CallFrame& call_frame) const override
{
EigenArray1d<ET>(call_frame, m_out) =
EigenArray1d<element::Bool>(call_frame, m_arg0)
.select(EigenArray1d<ET>(call_frame, m_arg1),
EigenArray1d<ET>(call_frame, m_arg2));
char* arg0 = get_tensor_data_ptr<element::Bool>(call_frame, m_arg0); // FIXME: temporarily char not bool
typename ET::type* arg1 = get_tensor_data_ptr<ET>(call_frame, m_arg1);
typename ET::type* arg2 = get_tensor_data_ptr<ET>(call_frame, m_arg2);
typename ET::type* out = get_tensor_data_ptr<ET>(call_frame, m_out);
size_t count = get_tensor_element_count(call_frame, m_arg0);
kernel::select<typename ET::type>(arg0, arg1, arg2, out, count);
}
protected:
......
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