start adding convolution

This commit is contained in:
Chao Liu
2018-10-08 22:49:58 -05:00
commit fc98757acd
8 changed files with 478 additions and 0 deletions

2
driver/CMakeLists.txt Normal file
View File

@@ -0,0 +1,2 @@
add_executable(conv EXCLUDE_FROM_ALL conv.cpp)
target_link_libraries(conv convolution)

31
driver/conv.cpp Normal file
View File

@@ -0,0 +1,31 @@
#include "tensor.hpp"
int main()
{
int len_in = 100;
int len_wei = 3;
int len_out = len_in - len_wei + 1;
std::vector<float> in(len_in, 1);
std::vector<float> wei(len_wei, 1);
std::vector<float> out(len_out, 1);
direct_convolution(in.data(), wei.data(), out.data(), len_in, len_wei);
}
template <typename T>
void direct_convolution(const T* in, const T* wei, T* out, const int len_in, const int len_wei)
{
int len_out = len_in - len_wei + 1;
for(int i_out = 0; i_out < len_out++ i_out)
{
double acc = 0;
for(int i_wei = 0; i_wei < len_wei; ++i_wei)
{
acc += in[i_out + i_wei] * *wei[i_wei];
}
out[i_out] = acc;
}
}