-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation/testing for relu() and relup().
- Loading branch information
1 parent
2a0d493
commit 18f84a8
Showing
7 changed files
with
968 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2020, 2021, 2022, 2023 Francesco Biscani ([email protected]), Dario Izzo ([email protected]) | ||
// | ||
// This file is part of the heyoka library. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla | ||
// Public License v. 2.0. If a copy of the MPL was not distributed | ||
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#ifndef HEYOKA_MATH_RELU_HPP | ||
#define HEYOKA_MATH_RELU_HPP | ||
|
||
#include <cstdint> | ||
// #include <string> | ||
#include <vector> | ||
|
||
#include <heyoka/config.hpp> | ||
// #include <heyoka/detail/func_cache.hpp> | ||
#include <heyoka/detail/fwd_decl.hpp> | ||
#include <heyoka/detail/llvm_fwd.hpp> | ||
#include <heyoka/detail/visibility.hpp> | ||
#include <heyoka/func.hpp> | ||
#include <heyoka/s11n.hpp> | ||
|
||
HEYOKA_BEGIN_NAMESPACE | ||
|
||
namespace detail | ||
{ | ||
|
||
class HEYOKA_DLL_PUBLIC relu_impl : public func_base | ||
{ | ||
friend class boost::serialization::access; | ||
template <typename Archive> | ||
void serialize(Archive &ar, unsigned) | ||
{ | ||
ar &boost::serialization::base_object<func_base>(*this); | ||
} | ||
|
||
public: | ||
relu_impl(); | ||
explicit relu_impl(expression); | ||
|
||
[[nodiscard]] expression normalise() const; | ||
|
||
[[nodiscard]] std::vector<expression> gradient() const; | ||
|
||
[[nodiscard]] llvm::Value *llvm_eval(llvm_state &, llvm::Type *, const std::vector<llvm::Value *> &, llvm::Value *, | ||
llvm::Value *, llvm::Value *, std::uint32_t, bool) const; | ||
|
||
[[nodiscard]] llvm::Function *llvm_c_eval_func(llvm_state &, llvm::Type *, std::uint32_t, bool) const; | ||
|
||
llvm::Value *taylor_diff(llvm_state &, llvm::Type *, const std::vector<std::uint32_t> &, | ||
const std::vector<llvm::Value *> &, llvm::Value *, llvm::Value *, std::uint32_t, | ||
std::uint32_t, std::uint32_t, std::uint32_t, bool) const; | ||
|
||
llvm::Function *taylor_c_diff_func(llvm_state &, llvm::Type *, std::uint32_t, std::uint32_t, bool) const; | ||
}; | ||
|
||
class HEYOKA_DLL_PUBLIC relup_impl : public func_base | ||
{ | ||
friend class boost::serialization::access; | ||
template <typename Archive> | ||
void serialize(Archive &ar, unsigned) | ||
{ | ||
ar &boost::serialization::base_object<func_base>(*this); | ||
} | ||
|
||
public: | ||
relup_impl(); | ||
explicit relup_impl(expression); | ||
|
||
[[nodiscard]] expression normalise() const; | ||
|
||
[[nodiscard]] std::vector<expression> gradient() const; | ||
|
||
[[nodiscard]] llvm::Value *llvm_eval(llvm_state &, llvm::Type *, const std::vector<llvm::Value *> &, llvm::Value *, | ||
llvm::Value *, llvm::Value *, std::uint32_t, bool) const; | ||
|
||
[[nodiscard]] llvm::Function *llvm_c_eval_func(llvm_state &, llvm::Type *, std::uint32_t, bool) const; | ||
|
||
llvm::Value *taylor_diff(llvm_state &, llvm::Type *, const std::vector<std::uint32_t> &, | ||
const std::vector<llvm::Value *> &, llvm::Value *, llvm::Value *, std::uint32_t, | ||
std::uint32_t, std::uint32_t, std::uint32_t, bool) const; | ||
|
||
llvm::Function *taylor_c_diff_func(llvm_state &, llvm::Type *, std::uint32_t, std::uint32_t, bool) const; | ||
}; | ||
|
||
} // namespace detail | ||
|
||
HEYOKA_DLL_PUBLIC expression relu(expression); | ||
|
||
HEYOKA_DLL_PUBLIC expression relup(expression); | ||
|
||
HEYOKA_END_NAMESPACE | ||
|
||
HEYOKA_S11N_FUNC_EXPORT_KEY(heyoka::detail::relu_impl) | ||
|
||
HEYOKA_S11N_FUNC_EXPORT_KEY(heyoka::detail::relup_impl) | ||
|
||
#endif |
Oops, something went wrong.