-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving autograd from header only lib to a compiled lib
- Loading branch information
Showing
6 changed files
with
267 additions
and
176 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,50 @@ | ||
cmake_minimum_required(VERSION 3.5.2) | ||
cmake_minimum_required(VERSION 3.5.1) | ||
|
||
project(ArrayFireML | ||
VERSION 0.1.0 | ||
LANGUAGES C CXX) | ||
|
||
find_package(ArrayFire REQUIRED) | ||
set(ArrayFireML_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
|
||
add_library(afml SHARED "") | ||
|
||
target_sources(afml | ||
PRIVATE | ||
src/autograd/Variable.cpp | ||
src/autograd/Functions.cpp | ||
) | ||
|
||
target_include_directories(afml | ||
PUBLIC | ||
${ArrayFire_INCLUDE_DIRS} | ||
${CMAKE_CURRENT_SOURCE_DIR}/include | ||
) | ||
|
||
target_compile_features(afml | ||
PRIVATE | ||
cxx_range_for | ||
cxx_auto_type | ||
cxx_lambdas | ||
cxx_long_long_type | ||
cxx_nullptr | ||
cxx_raw_string_literals | ||
cxx_right_angle_brackets | ||
cxx_static_assert | ||
cxx_thread_local | ||
cxx_uniform_initialization | ||
cxx_variadic_templates | ||
) | ||
|
||
target_link_libraries(afml | ||
PUBLIC | ||
af | ||
) | ||
|
||
set_target_properties(afml | ||
PROPERTIES | ||
VERSION "${ArrayFireML_VERSION}" | ||
SOVERSION "${ArrayFireML_VERSION_MAJOR}" | ||
) | ||
|
||
|
||
add_subdirectory(examples) |
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
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,37 @@ | ||
/******************************************************* | ||
* Copyright (c) 2017, ArrayFire | ||
* All rights reserved. | ||
* | ||
* This file is distributed under 3-clause BSD license. | ||
* The complete license agreement can be obtained at: | ||
* http://arrayfire.com/licenses/BSD-3-Clause | ||
********************************************************/ | ||
|
||
#include <af/autograd/Variable.hpp> | ||
#include <af/autograd/Functions.hpp> | ||
|
||
namespace af { | ||
namespace autograd { | ||
|
||
Variable operator +(const Variable lhs, const Variable rhs) | ||
{ | ||
auto result = lhs.array() + rhs.array(); | ||
auto grad_func = [](std::vector<Variable> inputs, Variable grad_output) { | ||
inputs[0].addGrad(grad_output); | ||
inputs[1].addGrad(grad_output); | ||
}; | ||
return Variable(result, {lhs, rhs}, grad_func); | ||
} | ||
|
||
Variable operator *(const Variable lhs, const Variable rhs) | ||
{ | ||
auto result = lhs.array() * rhs.array(); | ||
auto grad_func = [](std::vector<Variable> inputs, Variable grad_output) { | ||
inputs[0].addGrad(grad_output * inputs[1]); | ||
inputs[1].addGrad(grad_output * inputs[0]); | ||
}; | ||
return Variable(result, {lhs, rhs}, grad_func); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.