Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fpga develop #209

Merged
merged 18 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,371 changes: 672 additions & 699 deletions fpga_kernels/kernel_conv2D_K3x3_S1x1_P1x1_BS1.cpp

Large diffs are not rendered by default.

366 changes: 257 additions & 109 deletions fpga_kernels/test_fpga/src/test_conv2D_K3x3_S1x1_P1x1_BS1.cpp

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion include/eddl/apis/eddl.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,14 +677,21 @@ namespace eddl {
* @param l Layer to detach
* @return Detached Layer
*/
layer detach(layer l);/**
layer detach(layer l);

/**
* @brief Sets the provided layers as detached, excluding them from the computation of the gradients.
*
* @param l Layers to detach
* @return Detached Layers
*/
vlayer detach(vlayer l);

/**
* @brief Shows profile information.
*/
void show_profile();


///////////////////////////////////////
// LAYERS
Expand Down
2 changes: 2 additions & 0 deletions include/eddl/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ string printVector(vector<T> myvector){
enum WrappingMode {Constant=0, Reflect=1, Nearest=2, Mirror=3, Wrap=4, Original=5};
WrappingMode getWrappingMode(string mode);

void __show_profile();

#endif //EDDL_UTILS_H
6 changes: 6 additions & 0 deletions src/apis/eddl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <stdexcept>

#include "eddl/apis/eddl.h"
#include "eddl/utils.h"


using namespace std;
Expand Down Expand Up @@ -295,6 +296,11 @@ namespace eddl {
net->train_batch(in, out, indices,1);
}

void show_profile() {
printf("profile:\n");
__show_profile();
}

void next_batch(vector<Tensor *> in,vector<Tensor *> out)
{
int i,n;
Expand Down
10 changes: 0 additions & 10 deletions src/net/net_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ void *update_t(void *t) {
}
/////////////////////////////////////////




/////////////////////////////////////////
// "a ring to rule them all"
void Net::run_snets(void *(*F)(void *t))
Expand Down Expand Up @@ -1113,11 +1110,4 @@ vtensor Net::predict(vtensor tin) {

}








//////
1 change: 0 additions & 1 deletion src/tensor/nn/tensor_activations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ namespace tensorNN {
B->tsem->unlock();

PROFILING_FOOTER(ReLu);
PROFILING_PRINTF(ReLu);
}

// RELU Derivative, always increment over parent delta
Expand Down
57 changes: 57 additions & 0 deletions src/tensor/tensor_da.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "eddl/tensor/tensor.h"
#include "eddl/hardware/cpu/cpu_tensor.h"
#include "eddl/profiling.h"

#ifdef cGPU
#include "eddl/hardware/gpu/gpu_tensor.h"
Expand Down Expand Up @@ -48,6 +49,8 @@ void Tensor::shift(Tensor *A, Tensor *B, vector<int> shift, WrappingMode mode, f
msg("This method requires two 4D tensors", "Tensor::shift");
}

PROFILING_HEADER_EXTERN(shift);

if (A->isCPU()) {
cpu_shift(A, B, std::move(shift), mode, cval);
}
Expand All @@ -62,6 +65,8 @@ void Tensor::shift(Tensor *A, Tensor *B, vector<int> shift, WrappingMode mode, f
fpga_shift(A, B, std::move(shift), mode, cval);
}
#endif

PROFILING_FOOTER(shift);
}

Tensor* Tensor::rotate(float angle, vector<int> offset_center, WrappingMode mode, float cval){
Expand All @@ -78,6 +83,8 @@ void Tensor::rotate(Tensor *A, Tensor *B, float angle, vector<int> offset_center
msg("This method requires two 4D tensors", "Tensor::rotate");
}

PROFILING_HEADER_EXTERN(rotate);

if (A->isCPU()) {
cpu_rotate(A, B, angle, std::move(offset_center), mode, cval);
}
Expand All @@ -92,6 +99,8 @@ void Tensor::rotate(Tensor *A, Tensor *B, float angle, vector<int> offset_center
fpga_rotate(A, B, angle, std::move(offset_center), mode, cval);
}
#endif

PROFILING_FOOTER(rotate);
}

Tensor* Tensor::scale(vector<int> new_shape, WrappingMode mode, float cval, bool keep_size) {
Expand Down Expand Up @@ -120,6 +129,8 @@ void Tensor::scale(Tensor *A, Tensor *B, vector<int> new_shape, WrappingMode mod
msg("This method requires two 4D tensors", "Tensor::scale");
}

PROFILING_HEADER_EXTERN(scale);

if (A->isCPU()) {
cpu_scale(A, B, std::move(new_shape), mode, cval);
}
Expand All @@ -134,6 +145,8 @@ void Tensor::scale(Tensor *A, Tensor *B, vector<int> new_shape, WrappingMode mod
fpga_scale(A, B, std::move(new_shape), mode, cval);
}
#endif

PROFILING_FOOTER(scale);
}


Expand All @@ -156,6 +169,8 @@ void Tensor::flip(Tensor *A, Tensor *B, int axis) {
msg("This method requires two 4D tensors", "Tensor::flip");
}

PROFILING_HEADER_EXTERN(flip);

if (A->isCPU()) {
cpu_flip(A, B, axis);
}
Expand All @@ -170,6 +185,8 @@ void Tensor::flip(Tensor *A, Tensor *B, int axis) {
fpga_flip(A, B, axis);
}
#endif

PROFILING_FOOTER(flip);
}

Tensor* Tensor::crop(vector<int> coords_from, vector<int> coords_to, float cval, bool keep_size){
Expand Down Expand Up @@ -200,6 +217,8 @@ void Tensor::crop(Tensor *A, Tensor *B, vector<int> coords_from, vector<int> coo
msg("This method requires two 4D tensors", "Tensor::crop");
}

PROFILING_HEADER_EXTERN(crop);

if (A->isCPU()) {
cpu_crop(A, B, std::move(coords_from), std::move(coords_to), cval, false);
}
Expand All @@ -214,6 +233,8 @@ void Tensor::crop(Tensor *A, Tensor *B, vector<int> coords_from, vector<int> coo
fpga_crop(A, B, std::move(coords_from), std::move(coords_to), cval, false);
}
#endif

PROFILING_FOOTER(crop);
}

Tensor* Tensor::crop_scale(vector<int> coords_from, vector<int> coords_to, WrappingMode mode, float cval){
Expand All @@ -237,6 +258,8 @@ void Tensor::crop_scale(Tensor *A, Tensor *B, vector<int> coords_from, vector<in
msg("This method requires two 4D tensors", "Tensor::crop_scale");
}

PROFILING_HEADER_EXTERN(crop_scale);

if (A->isCPU()) {
cpu_crop_scale(A, B, std::move(coords_from), std::move(coords_to), mode, cval);
}
Expand All @@ -251,6 +274,8 @@ void Tensor::crop_scale(Tensor *A, Tensor *B, vector<int> coords_from, vector<in
fpga_crop_scale(A, B, std::move(coords_from), std::move(coords_to), mode, cval);
}
#endif

PROFILING_FOOTER(crop_scale);
}


Expand All @@ -277,6 +302,8 @@ void Tensor::cutout(Tensor *A, Tensor *B, vector<int> coords_from, vector<int> c
msg("This method requires two 4D tensors", "Tensor::cutout");
}

PROFILING_HEADER_EXTERN(cutout);

if (A->isCPU()) {
cpu_crop(A, B, std::move(coords_from), std::move(coords_to), cval, true);
}
Expand All @@ -291,6 +318,8 @@ void Tensor::cutout(Tensor *A, Tensor *B, vector<int> coords_from, vector<int> c
fpga_crop(A, B, std::move(coords_from), std::move(coords_to), cval, true);
}
#endif

PROFILING_FOOTER(cutout);
}


Expand Down Expand Up @@ -318,6 +347,8 @@ void Tensor::shift_random(Tensor *A, Tensor *B, vector<float> factor_x, vector<f
msg("This method requires two 4D tensors", "Tensor::shift_random");
}

PROFILING_HEADER_EXTERN(shift_random);

if (A->isCPU()) {
cpu_shift_random(A, B, std::move(factor_x), std::move(factor_y), mode, cval);
}
Expand All @@ -332,6 +363,8 @@ void Tensor::shift_random(Tensor *A, Tensor *B, vector<float> factor_x, vector<f
fpga_shift_random(A, B, std::move(factor_x), std::move(factor_y), mode, cval);
}
#endif

PROFILING_FOOTER(shift_random);
}


Expand All @@ -349,6 +382,8 @@ void Tensor::rotate_random(Tensor *A, Tensor *B, vector<float> factor, vector<in
msg("This method requires two 4D tensors", "Tensor::rotate_random");
}

PROFILING_HEADER_EXTERN(rotate_random);

if (A->isCPU()) {
cpu_rotate_random(A, B, std::move(factor), std::move(offset_center), mode, cval);
}
Expand All @@ -363,6 +398,8 @@ void Tensor::rotate_random(Tensor *A, Tensor *B, vector<float> factor, vector<in
fpga_rotate_random(A, B, std::move(factor), std::move(offset_center), mode, cval);
}
#endif

PROFILING_FOOTER(rotate_random);
}

Tensor* Tensor::scale_random(vector<float> factor, WrappingMode mode, float cval){
Expand All @@ -384,6 +421,8 @@ void Tensor::scale_random(Tensor *A, Tensor *B, vector<float> factor, WrappingMo
msg("This method requires two 4D tensors", "Tensor::scale_random");
}

PROFILING_HEADER_EXTERN(scale_random);

if (A->isCPU()) {
cpu_scale_random(A, B, std::move(factor), mode, cval);
}
Expand All @@ -398,6 +437,8 @@ void Tensor::scale_random(Tensor *A, Tensor *B, vector<float> factor, WrappingMo
fpga_scale_random(A, B, std::move(factor), mode, cval);
}
#endif

PROFILING_FOOTER(scale_random);
}


Expand All @@ -420,6 +461,8 @@ void Tensor::flip_random(Tensor *A, Tensor *B, int axis) {
msg("This method requires two 4D tensors", "Tensor::flip_random");
}

PROFILING_HEADER_EXTERN(flip_random);

if (A->isCPU()) {
cpu_flip_random(A, B, axis);
}
Expand All @@ -434,6 +477,8 @@ void Tensor::flip_random(Tensor *A, Tensor *B, int axis) {
fpga_flip_random(A, B, axis);
}
#endif

PROFILING_FOOTER(flip_random);
}

Tensor* Tensor::crop_random(int height, int width, float cval, bool keep_size){
Expand Down Expand Up @@ -464,6 +509,8 @@ void Tensor::crop_random(Tensor *A, Tensor *B) {
msg("This method requires two 4D tensors", "Tensor::crop_random");
}

PROFILING_HEADER_EXTERN(crop_random);

if (A->isCPU()) {
cpu_crop_random(A, B);
}
Expand All @@ -478,6 +525,8 @@ void Tensor::crop_random(Tensor *A, Tensor *B) {
fpga_crop_random(A, B);
}
#endif

PROFILING_FOOTER(crop_random);
}

Tensor* Tensor::crop_scale_random(vector<float> factor, WrappingMode mode, float cval){
Expand All @@ -498,6 +547,8 @@ void Tensor::crop_scale_random(Tensor *A, Tensor *B, vector<float> factor, Wrapp
msg("This method requires two 4D tensors", "Tensor::crop_scale_random");
}

PROFILING_HEADER_EXTERN(crop_scale_random);

if (A->isCPU()) {
cpu_crop_scale_random(A, B, std::move(factor), mode, cval);
}
Expand All @@ -512,6 +563,8 @@ void Tensor::crop_scale_random(Tensor *A, Tensor *B, vector<float> factor, Wrapp
fpga_crop_scale_random(A, B, std::move(factor), mode, cval);
}
#endif

PROFILING_FOOTER(crop_scale_random);
}

Tensor* Tensor::cutout_random(vector<float> factor_x, vector<float> factor_y, float cval){
Expand All @@ -536,6 +589,8 @@ void Tensor::cutout_random(Tensor *A, Tensor *B, vector<float> factor_x, vector<
msg("This method requires two 4D tensors", "Tensor::cutout_random");
}

PROFILING_HEADER_EXTERN(cutout_random);

if (A->isCPU()) {
cpu_cutout_random(A, B, std::move(factor_x), std::move(factor_y), cval);
}
Expand All @@ -550,4 +605,6 @@ void Tensor::cutout_random(Tensor *A, Tensor *B, vector<float> factor_x, vector<
fpga_cutout_random(A, B, std::move(factor_x), std::move(factor_y), cval);
}
#endif

PROFILING_FOOTER(cutout_random);
}
Loading