2019-06-06 14:21:15 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2015-2018 Skymind, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <types/float16.h>
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <system/dll.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
#include <helpers/RandomLauncher.h>
|
|
|
|
#include <graph/RandomGenerator.h>
|
2019-08-07 14:29:17 +02:00
|
|
|
//#include <ops/declarable/CustomOperations.h>
|
2019-07-15 15:36:35 +02:00
|
|
|
#include <helpers/PointersManager.h>
|
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
|
|
|
// FIXME: implement this
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
void RandomLauncher::applyDropOut(sd::LaunchContext *context, sd::graph::RandomGenerator& rng, NDArray *array, double retainProb, NDArray* z) {
|
2019-06-06 14:21:15 +02:00
|
|
|
if (z == nullptr)
|
|
|
|
z = array;
|
|
|
|
|
|
|
|
ExtraArguments arguments({retainProb});
|
2019-07-15 15:36:35 +02:00
|
|
|
PointersManager pm(context, "applyDropOut");
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-07-15 15:36:35 +02:00
|
|
|
NativeOpExecutioner::execRandom(context, random::DropOut, &rng, array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), z->buffer(), z->shapeInfo(), z->specialBuffer(), z->specialShapeInfo(), arguments.argumentsAsT(z->dataType()));
|
|
|
|
pm.synchronize();
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
void RandomLauncher::applyInvertedDropOut(sd::LaunchContext *context, sd::graph::RandomGenerator& rng, NDArray *array, double retainProb, NDArray* z) {
|
2019-06-06 14:21:15 +02:00
|
|
|
if (z == nullptr)
|
|
|
|
z = array;
|
|
|
|
|
|
|
|
ExtraArguments arguments({retainProb});
|
2019-07-15 15:36:35 +02:00
|
|
|
PointersManager pm(context, "applyInvertedDropOut");
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-07-15 15:36:35 +02:00
|
|
|
NativeOpExecutioner::execRandom(context, random::DropOutInverted, &rng, array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), z->buffer(), z->shapeInfo(), z->specialBuffer(), z->specialShapeInfo(), arguments.argumentsAsT(z->dataType()));
|
|
|
|
pm.synchronize();
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
void RandomLauncher::applyAlphaDropOut(sd::LaunchContext *context, sd::graph::RandomGenerator& rng, NDArray *array, double retainProb, double alpha, double beta, double alphaPrime, NDArray* z) {
|
2019-06-06 14:21:15 +02:00
|
|
|
if (z == nullptr)
|
|
|
|
z = array;
|
|
|
|
|
|
|
|
ExtraArguments arguments({retainProb, alpha, beta, alphaPrime});
|
2019-07-15 15:36:35 +02:00
|
|
|
PointersManager pm(context, "applyAlphaDropOut");
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-07-15 15:36:35 +02:00
|
|
|
NativeOpExecutioner::execRandom(context, random::AlphaDropOut, &rng, array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), z->buffer(), z->shapeInfo(), z->specialBuffer(), z->specialShapeInfo(), arguments.argumentsAsT(z->dataType()));
|
|
|
|
pm.synchronize();
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
void RandomLauncher::fillBernoulli(sd::LaunchContext *context, sd::graph::RandomGenerator& rng, NDArray* array, double prob) {
|
2019-06-06 14:21:15 +02:00
|
|
|
ExtraArguments arguments({prob});
|
2019-07-15 15:36:35 +02:00
|
|
|
PointersManager pm(context, "fillBernoulli");
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-07-15 15:36:35 +02:00
|
|
|
NativeOpExecutioner::execRandom(context, random::BernoulliDistribution, &rng, array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), arguments.argumentsAsT(array->dataType()));
|
|
|
|
pm.synchronize();
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
void RandomLauncher::fillUniform(sd::LaunchContext *context, sd::graph::RandomGenerator& rng, NDArray* array, double from, double to) {
|
2019-06-06 14:21:15 +02:00
|
|
|
ExtraArguments arguments({from, to});
|
2019-07-15 15:36:35 +02:00
|
|
|
PointersManager pm(context, "fillUniform");
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-07-15 15:36:35 +02:00
|
|
|
NativeOpExecutioner::execRandom(context, random::UniformDistribution, &rng, array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), arguments.argumentsAsT(array->dataType()));
|
|
|
|
pm.synchronize();
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
void RandomLauncher::fillGaussian(sd::LaunchContext *context, sd::graph::RandomGenerator& rng, NDArray* array, double mean, double stdev) {
|
2019-06-06 14:21:15 +02:00
|
|
|
ExtraArguments arguments({mean, stdev});
|
2019-07-15 15:36:35 +02:00
|
|
|
PointersManager pm(context, "fillGaussian");
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-07-15 15:36:35 +02:00
|
|
|
NativeOpExecutioner::execRandom(context, random::GaussianDistribution, &rng, array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), arguments.argumentsAsT(array->dataType()));
|
|
|
|
pm.synchronize();
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
void RandomLauncher::fillExponential(sd::LaunchContext *context, sd::graph::RandomGenerator& rng, NDArray* array, double lambda) {
|
2019-06-06 14:21:15 +02:00
|
|
|
ExtraArguments arguments({lambda});
|
2019-07-15 15:36:35 +02:00
|
|
|
PointersManager pm(context, "fillExponential");
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-07-15 15:36:35 +02:00
|
|
|
NativeOpExecutioner::execRandom(context, random::ExponentialDistribution, &rng, array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), arguments.argumentsAsT(array->dataType()));
|
|
|
|
pm.synchronize();
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
void RandomLauncher::fillLogNormal(sd::LaunchContext *context, sd::graph::RandomGenerator& rng, NDArray* array, double mean, double stdev) {
|
2019-06-06 14:21:15 +02:00
|
|
|
ExtraArguments arguments({mean, stdev});
|
2019-07-15 15:36:35 +02:00
|
|
|
PointersManager pm(context, "fillLogNormal");
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-07-15 15:36:35 +02:00
|
|
|
NativeOpExecutioner::execRandom(context, random::GaussianDistribution, &rng, array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), arguments.argumentsAsT(array->dataType()));
|
|
|
|
pm.synchronize();
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
void RandomLauncher::fillTruncatedNormal(sd::LaunchContext *context, sd::graph::RandomGenerator& rng, NDArray* array, double mean, double stdev) {
|
2019-06-06 14:21:15 +02:00
|
|
|
ExtraArguments arguments({mean, stdev});
|
2019-07-15 15:36:35 +02:00
|
|
|
PointersManager pm(context, "fillTruncatedNormal");
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-07-15 15:36:35 +02:00
|
|
|
NativeOpExecutioner::execRandom(context, random::TruncatedNormalDistribution, &rng, array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), arguments.argumentsAsT(array->dataType()));
|
|
|
|
pm.synchronize();
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
void RandomLauncher::fillBinomial(sd::LaunchContext *context, sd::graph::RandomGenerator& rng, NDArray* array, int trials, double prob) {
|
2019-06-06 14:21:15 +02:00
|
|
|
ExtraArguments arguments({(double) trials, prob});
|
2019-07-15 15:36:35 +02:00
|
|
|
PointersManager pm(context, "fillBinomial");
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-07-15 15:36:35 +02:00
|
|
|
NativeOpExecutioner::execRandom(context, random::BinomialDistributionEx, &rng, array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), array->buffer(), array->shapeInfo(), array->specialBuffer(), array->specialShapeInfo(), arguments.argumentsAsT(array->dataType()));
|
|
|
|
pm.synchronize();
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
}
|