2019-04-25 16:17:36 -04:00
|
|
|
#include <cstring>
|
|
|
|
#include <cstdio>
|
2019-05-28 14:02:27 -04:00
|
|
|
#include <sstream>
|
2019-05-18 11:51:49 -04:00
|
|
|
#include "triton/runtime/jit.h"
|
2019-04-25 16:17:36 -04:00
|
|
|
#include "triton/driver/backend.h"
|
|
|
|
#include "triton/driver/stream.h"
|
2019-05-06 17:47:06 -04:00
|
|
|
#include "triton/dnn/conv.h"
|
2019-05-28 14:02:27 -04:00
|
|
|
#include "triton/tools/bench.hpp"
|
2019-04-25 16:17:36 -04:00
|
|
|
|
|
|
|
int main() {
|
|
|
|
// initialize default compute device
|
|
|
|
auto context = triton::driver::backend::contexts::get_default();
|
2019-05-20 12:20:29 -04:00
|
|
|
triton::dnn::conv::type ty = triton::dnn::conv::FPROP;
|
2019-04-25 16:17:36 -04:00
|
|
|
// initialization
|
2019-06-26 18:50:53 -07:00
|
|
|
int32_t B = 16, NF = 128;
|
|
|
|
int32_t D = 1, H = 16, W = 16;
|
|
|
|
int32_t NC = 64, T = 1, R = 3, S = 3;
|
2019-05-19 01:31:08 -04:00
|
|
|
int32_t pad_d = 0, pad_h = 0, pad_w = 0;
|
2019-05-20 12:20:29 -04:00
|
|
|
int32_t stride_d = 1, stride_h = 1, stride_w = 1;
|
|
|
|
int32_t upsample_d = 1, upsample_h = 1, upsample_w = 1;
|
2019-07-09 17:30:58 -07:00
|
|
|
// triton::dnn::conv configuration(128, 256, 1, 14, 14, 1, 5, 5, 512, 1, 1, 1, 0, 0, 0, 1, 1, 1, "fp32", "fp32", triton::dnn::conv::FPROP, 0);
|
|
|
|
triton::dnn::conv configuration(B, NC, D, H, W, T, R, S, NF,
|
|
|
|
stride_d, stride_h, stride_w,
|
|
|
|
pad_d, pad_h, pad_w,
|
|
|
|
upsample_d, upsample_h, upsample_w,
|
|
|
|
"fp32", "fp32", ty, 0);
|
2019-05-06 19:30:22 -04:00
|
|
|
// convolution configuration
|
2019-05-08 13:58:25 -04:00
|
|
|
std::vector<float> hc(configuration.c_size());
|
|
|
|
std::vector<float> rc(configuration.c_size());
|
|
|
|
std::vector<float> ha(configuration.a_size());
|
|
|
|
std::vector<float> hb(configuration.b_size());
|
2019-04-25 16:17:36 -04:00
|
|
|
srand(0);
|
|
|
|
for(size_t i = 0; i < ha.size(); i++)
|
2019-05-06 17:47:06 -04:00
|
|
|
ha[i] = (float)rand()/RAND_MAX;
|
2019-04-25 16:17:36 -04:00
|
|
|
for(size_t i = 0; i < hb.size(); i++)
|
2019-05-06 17:47:06 -04:00
|
|
|
hb[i] = (float)rand()/RAND_MAX;
|
2019-04-25 16:17:36 -04:00
|
|
|
for(size_t i = 0; i < hc.size(); i++)
|
2019-05-08 13:58:25 -04:00
|
|
|
hc[i] = 0;
|
2019-05-08 10:09:30 -04:00
|
|
|
rc = hc;
|
2019-04-25 16:17:36 -04:00
|
|
|
triton::driver::buffer* dc = triton::driver::buffer::create(context, hc.size()*4);
|
|
|
|
triton::driver::buffer* da = triton::driver::buffer::create(context, ha.size()*4);
|
|
|
|
triton::driver::buffer* db = triton::driver::buffer::create(context, hb.size()*4);
|
|
|
|
triton::driver::stream* stream = triton::driver::stream::create(context);
|
|
|
|
stream->write(da, true, 0, ha);
|
|
|
|
stream->write(db, true, 0, hb);
|
|
|
|
stream->write(dc, true, 0, hc);
|
|
|
|
stream->synchronize();
|
2019-07-09 17:30:58 -07:00
|
|
|
configuration.enqueue(stream, {da, db, dc, nullptr});
|
2019-04-25 16:17:36 -04:00
|
|
|
stream->read(dc, true, 0, hc);
|
2019-05-08 10:09:30 -04:00
|
|
|
configuration.cpu_ref(rc.data(), ha.data(), hb.data());
|
2019-05-11 18:09:23 -04:00
|
|
|
for(size_t i = 0; i < hc.size(); i++){
|
2019-05-15 14:57:31 -04:00
|
|
|
if(std::isnan(hc[i]) || std::abs(hc[i] - rc[i])/std::max(hc[i], rc[i]) > 1e-4){
|
2019-04-25 16:17:36 -04:00
|
|
|
std::cout << i << " " << hc[i] << " " << rc[i] << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
2019-05-13 00:38:26 -04:00
|
|
|
}
|
2019-05-11 18:09:23 -04:00
|
|
|
}
|
2019-04-25 16:17:36 -04:00
|
|
|
std::cout << "Pass!" << std::endl;
|
|
|
|
}
|