2019-04-25 16:17:36 -04:00
|
|
|
#include <cstring>
|
|
|
|
#include <cstdio>
|
2019-06-27 11:37:19 -07: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-28 14:02:27 -04:00
|
|
|
#include "triton/tools/bench.hpp"
|
2019-06-27 11:37:19 -07:00
|
|
|
#include "triton/dnn/shift.h"
|
2019-06-28 20:22:52 -07:00
|
|
|
#include "triton/external/half.hpp"
|
2019-04-25 16:17:36 -04:00
|
|
|
|
|
|
|
int main() {
|
2019-07-12 20:03:05 -07:00
|
|
|
typedef float NumericT;
|
|
|
|
std::string numeric_t_str = "fp32";
|
2019-06-28 20:22:52 -07:00
|
|
|
|
2019-04-25 16:17:36 -04:00
|
|
|
// initialize default compute device
|
|
|
|
auto context = triton::driver::backend::contexts::get_default();
|
2019-07-12 20:03:05 -07:00
|
|
|
auto op = triton::dnn::shift::FPROP;
|
2019-06-30 16:55:02 -07:00
|
|
|
|
2019-04-25 16:17:36 -04:00
|
|
|
// initialization
|
|
|
|
int32_t R = 3, S = 3;
|
2019-07-12 20:03:05 -07:00
|
|
|
int32_t B = 16, F = 4096;
|
2019-07-02 16:39:07 -07:00
|
|
|
int32_t H = 16, W = 16;
|
2019-07-12 20:03:05 -07:00
|
|
|
int32_t C = 4096;
|
2019-06-29 13:58:46 -07:00
|
|
|
|
2019-04-25 16:17:36 -04:00
|
|
|
// random shifts
|
|
|
|
std::vector<int32_t> shift_h(C);
|
|
|
|
std::vector<int32_t> shift_w(C);
|
|
|
|
for(int32_t c = 0; c < C; c++){
|
|
|
|
shift_h[c] = rand() % R - R/2;
|
|
|
|
shift_w[c] = rand() % S - S/2;
|
|
|
|
}
|
2019-06-27 11:37:19 -07:00
|
|
|
// configuration
|
2019-07-12 20:03:05 -07:00
|
|
|
triton::dnn::shift shift(B, C, 1, H, W, 1, R, S, F, 1, 1,
|
|
|
|
shift_h.data(), shift_w.data(),
|
|
|
|
numeric_t_str, numeric_t_str,
|
|
|
|
op, false);
|
2019-06-27 11:37:19 -07:00
|
|
|
// host buffers
|
2019-07-12 20:03:05 -07:00
|
|
|
std::vector<NumericT> ha(B*C*H*W);
|
|
|
|
std::vector<NumericT> hb(C*F);
|
|
|
|
std::vector<float> hc(B*F*H*W);
|
|
|
|
std::vector<float> rc(hc.size());
|
2019-06-27 11:37:19 -07:00
|
|
|
// device buffers
|
|
|
|
triton::driver::buffer* dc = triton::driver::buffer::create(context, hc.size()*4);
|
2019-06-28 20:22:52 -07:00
|
|
|
triton::driver::buffer* da = triton::driver::buffer::create(context, ha.size()*sizeof(NumericT));
|
|
|
|
triton::driver::buffer* db = triton::driver::buffer::create(context, hb.size()*sizeof(NumericT));
|
2019-06-27 11:37:19 -07:00
|
|
|
triton::driver::stream* stream = triton::driver::stream::create(context);
|
|
|
|
// initialize host
|
2019-04-25 16:17:36 -04:00
|
|
|
srand(0);
|
2019-06-27 11:37:19 -07:00
|
|
|
for(size_t i = 0; i < ha.size(); i++)
|
2019-06-28 20:22:52 -07:00
|
|
|
ha[i] = (NumericT)rand() / RAND_MAX;
|
2019-04-25 16:17:36 -04:00
|
|
|
for(size_t i = 0; i < hb.size(); i++)
|
2019-06-28 20:22:52 -07:00
|
|
|
hb[i] = (NumericT)rand() / RAND_MAX;
|
2019-04-25 16:17:36 -04:00
|
|
|
for(size_t i = 0; i < hc.size(); i++)
|
|
|
|
hc[i] = 0;
|
2019-06-27 11:37:19 -07:00
|
|
|
// initialize device
|
2019-04-25 16:17:36 -04:00
|
|
|
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
|
|
|
shift.enqueue(stream, {da, db, dc});
|
2019-06-28 20:22:52 -07:00
|
|
|
// stream->read(dc, true, 0, hc);
|
|
|
|
// shift.cpu_ref(rc.data(), ha.data(), hb.data());
|
|
|
|
// for(size_t i = 0; i < hc.size(); i++)
|
|
|
|
// if(std::isnan(hc[i]) || std::abs(hc[i] - rc[i])/std::max(hc[i], rc[i]) > 1e-4){
|
|
|
|
// std::cout << i << " " << hc[i] << " " << rc[i] << std::endl;
|
|
|
|
// exit(EXIT_FAILURE);
|
|
|
|
// }
|
|
|
|
// std::cout << "Pass!" << std::endl;
|
2019-04-25 16:17:36 -04:00
|
|
|
|
|
|
|
}
|