Skip to content

Commit

Permalink
Merge pull request #10 from sony/feature/20170808-insensitive_loss
Browse files Browse the repository at this point in the history
Implement epsilon insensitive loss of cuda version.
  • Loading branch information
TakuyaNarihira authored Aug 21, 2017
2 parents 6a4ef0a + 07ca0a8 commit 9e5a889
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/implements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ Function Implements
- x
-
* - HuberLoss
- x
-
* - EpsilonInsensitiveLoss
- x
-
* - SigmoidCrossEntropy
Expand Down
31 changes: 31 additions & 0 deletions include/nbla/cuda/function/epsilon_insensitive_loss.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2017 Sony Corporation. All Rights Reserved.
//
// 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.

/** EpsilonInsensitiveLoss
*/
#ifndef __NBLA_CUDA_FUNCTION_EPSILONINSENSITIVELOSS_HPP__
#define __NBLA_CUDA_FUNCTION_EPSILONINSENSITIVELOSS_HPP__

#include <nbla/cuda/common.hpp>
#include <nbla/cuda/cuda.hpp>
#include <nbla/cuda/function/utils/base_transform_binary.hpp>
#include <nbla/function/epsilon_insensitive_loss.hpp>

namespace nbla {
/** @copydoc EpsilonInsensitiveLoss
*/
NBLA_DECLARE_TRANSFORM_BINARY_CUDA_1(EpsilonInsensitiveLoss, float);
}

#endif
31 changes: 31 additions & 0 deletions src/nbla/cuda/function/epsilon_insensitive_loss.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2017 Sony Corporation. All Rights Reserved.
//
// 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 <nbla/array.hpp>
#include <nbla/cuda/common.hpp>
#include <nbla/cuda/function/epsilon_insensitive_loss.hpp>
#include <nbla/cuda/function/utils/base_transform_binary.cuh>
#include <nbla/cuda/math.hpp>
#include <nbla/variable.hpp>

namespace nbla {

NBLA_DEFINE_TRANSFORM_BINARY_CUDA_1(
EpsilonInsensitiveLoss,
(fabs(x0 - x1) > (T)a0) ? (fabs((x0 - x1)) - (T)a0) : (T)0,
(x0 - x1) > (T)a0 ? dy : ((x0 - x1) < (T)-a0) ? -dy : (T)0,
(x0 - x1) > (T)a0 ? -dy : ((x0 - x1) < (T)-a0) ? dy : (T)0, float);
// template instantiation
template class EpsilonInsensitiveLossCuda<float>;
}

0 comments on commit 9e5a889

Please sign in to comment.