2021-02-01 13:31:45 +01:00
|
|
|
/* ******************************************************************************
|
|
|
|
*
|
2019-09-11 20:50:28 +02: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.
|
|
|
|
*
|
2021-02-01 13:31:45 +01:00
|
|
|
* See the NOTICE file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2019-09-11 20:50:28 +02:00
|
|
|
* 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
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
//
|
|
|
|
// @author raver119@gmail.com
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef SD_PLATFORMHELPER_H
|
|
|
|
#define SD_PLATFORMHELPER_H
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <helpers/ShapeUtils.h>
|
2020-01-20 19:32:46 +01:00
|
|
|
#include <execution/Engine.h>
|
2019-09-11 20:50:28 +02:00
|
|
|
#include <graph/Context.h>
|
|
|
|
#include <string>
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <system/pointercast.h>
|
|
|
|
#include <system/dll.h>
|
2019-09-11 20:50:28 +02:00
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
namespace sd {
|
2019-09-11 20:50:28 +02:00
|
|
|
namespace ops {
|
|
|
|
namespace platforms {
|
|
|
|
/**
|
|
|
|
* This abstract class defines methods used by platform-specific helpers implementations
|
|
|
|
*/
|
|
|
|
class ND4J_EXPORT PlatformHelper {
|
|
|
|
protected:
|
2020-01-20 19:32:46 +01:00
|
|
|
// target engine for this impl
|
2020-03-09 06:22:49 +01:00
|
|
|
samediff::Engine _engine;
|
2020-01-20 19:32:46 +01:00
|
|
|
|
2019-09-11 20:50:28 +02:00
|
|
|
// name of the operation this helper is built for
|
|
|
|
std::string _name;
|
|
|
|
|
|
|
|
// hash of the operation this helper is built for
|
|
|
|
Nd4jLong _hash;
|
|
|
|
public:
|
2020-03-09 06:22:49 +01:00
|
|
|
PlatformHelper(const char *name, samediff::Engine engine);
|
2019-09-11 20:50:28 +02:00
|
|
|
|
|
|
|
~PlatformHelper() = default;
|
|
|
|
|
|
|
|
std::string name();
|
|
|
|
|
2020-03-09 06:22:49 +01:00
|
|
|
samediff::Engine engine();
|
2020-01-20 19:32:46 +01:00
|
|
|
|
2019-09-11 20:50:28 +02:00
|
|
|
Nd4jLong hash();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method checks, if given helper can be used with given input/output/configuration options
|
|
|
|
*
|
|
|
|
* @param context
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
virtual bool isUsable(graph::Context &context) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method invokes helper. Typically this method replaces actual op execution
|
|
|
|
*
|
|
|
|
* @param context
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
virtual Nd4jStatus invokeHelper(graph::Context &context) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method, needed for compatibility with DeclarableOp macros
|
|
|
|
* @param ctx
|
|
|
|
* @param inputId
|
|
|
|
* @return
|
|
|
|
*/
|
2020-03-20 06:49:28 +01:00
|
|
|
sd::NDArray* getZ(graph::Context &ctx, int inputId);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method, needed for compatibility with DeclarableOp macros
|
|
|
|
* @param ctx
|
|
|
|
* @param inputId
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
sd::NDArray* getNullifiedZ(graph::Context &ctx, int inputId);
|
2019-09-11 20:50:28 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif //SD_PLATFORMHELPER_H
|