2021-02-09 05:16:31 +01:00
|
|
|
/*
|
|
|
|
* ******************************************************************************
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
* * This program and the accompanying materials are made available under the
|
|
|
|
* * terms of the Apache License, Version 2.0 which is available at
|
|
|
|
* * https://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
* *
|
|
|
|
* * See the NOTICE file distributed with this work for additional
|
|
|
|
* * information regarding copyright ownership.
|
|
|
|
* * 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.
|
|
|
|
* *
|
|
|
|
* * SPDX-License-Identifier: Apache-2.0
|
|
|
|
* *****************************************************************************
|
|
|
|
*/
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Created by saudet on 8/30/2018.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef LIBND4J_MKLDNNSTREAM_H
|
|
|
|
#define LIBND4J_MKLDNNSTREAM_H
|
|
|
|
|
2019-09-11 20:50:28 +02:00
|
|
|
#if !defined(__STANDALONE_BUILD__)
|
2019-06-06 14:21:15 +02:00
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2019-09-11 20:50:28 +02:00
|
|
|
#if defined(HAVE_MKLDNN)
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
namespace sd {
|
2019-06-06 14:21:15 +02:00
|
|
|
class MKLDNNStream {
|
|
|
|
protected:
|
|
|
|
std::string _opName;
|
|
|
|
|
|
|
|
std::vector<const NDArray*> _inputs;
|
|
|
|
std::vector<const NDArray*> _outputs;
|
|
|
|
std::vector<float> _floatArguments;
|
|
|
|
std::vector<int> _intArguments;
|
|
|
|
|
|
|
|
public:
|
|
|
|
template <typename X, typename Y>
|
|
|
|
static bool isSupported() {
|
2019-09-11 20:50:28 +02:00
|
|
|
// FIXME: strict float support doesn't work anymore
|
2019-06-06 14:21:15 +02:00
|
|
|
return typeid(X) == typeid(float) && typeid(Y) == typeid(float);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isSupported(const std::vector<const NDArray*> &arrays) {
|
2019-09-11 20:50:28 +02:00
|
|
|
// FIXME: strict float support doesn't work anymore
|
|
|
|
for (auto v:arrays) {
|
2020-03-02 10:49:41 +01:00
|
|
|
if (v != nullptr && v->dataType() != sd::DataType::FLOAT32) {
|
2019-06-06 14:21:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-11 20:50:28 +02:00
|
|
|
explicit MKLDNNStream(const std::string &opName) : _opName(opName) { }
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
bool checkAndReset(const std::vector<const NDArray*> &inputs, const std::vector<const NDArray*> &outputs,
|
|
|
|
const std::vector<float> &floatArguments, const std::vector<int> &intArguments) {
|
|
|
|
if (inputs != _inputs || outputs != _outputs || floatArguments != _floatArguments || intArguments != _intArguments) {
|
|
|
|
_inputs = inputs;
|
|
|
|
_outputs = outputs;
|
|
|
|
_floatArguments = floatArguments;
|
|
|
|
_intArguments = intArguments;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif //LIBND4J_MKLDNNSTREAM_H
|