main.c 1.6 KB
Newer Older
1 2
#include "libclient.h"

H
Helin Wang 已提交
3
//#include "gtest/gtest.h"
4

H
Helin Wang 已提交
5 6 7 8 9 10
void panic() {
  // TODO(helin): fix: gtest using cmake is not working, using this
  // hacky way for now.
  *(void*)0;
}

11
int main() {
H
Helin Wang 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
  char addr[] = "localhost:3000";
  client c = paddle_new_pserver_client(addr);
 retry:
  if (paddle_begin_init_params(c, NULL, 0)) {
    paddle_parameter param;
    char name_a[] = "param_a";
    char name_b[] = "param_b";
    char content[] = {0x00, 0x11, 0x22};
    param.element_type = PADDLE_ELEMENT_TYPE_FLOAT32;
    param.name = name_a;
    param.content = content;
    param.content_len = 3;
    if (paddle_init_param(c, param, NULL, 0) != 0) {
      goto retry;
    }
    param.element_type = PADDLE_ELEMENT_TYPE_INT32;
    param.name = name_b;
    param.content = content;
    param.content_len = 3;
    if (paddle_init_param(c, param, NULL, 0) != 0) {
      goto retry;
    }
    if (paddle_finish_init_params(c) != 0) {
      goto retry;
    }
  } else {
    panic();
  }

  char content[] = {0x00, 0x11, 0x22};
H
Helin Wang 已提交
42 43 44
  paddle_gradient grads[2] = {{"param_a", PADDLE_ELEMENT_TYPE_INT32, content, 3}, {"param_b", PADDLE_ELEMENT_TYPE_FLOAT32, content, 3}};

  if (!paddle_send_grads(c, grads, 2)) {
H
Helin Wang 已提交
45 46 47
    panic();
  }

H
Helin Wang 已提交
48
  paddle_parameter* params[2] = {NULL, NULL};
H
Helin Wang 已提交
49
  char* names[]={"param_a", "param_b"};
H
Helin Wang 已提交
50
  if (!paddle_get_params(c, names, params, 2)) {
H
Helin Wang 已提交
51 52 53
    panic();
  }

H
Helin Wang 已提交
54 55 56 57 58
  // get parameters again by reusing the allocated parameter buffers.
  if (!paddle_get_params(c, names, params, 2)) {
    panic();
  }

H
Helin Wang 已提交
59 60
  paddle_release_param(params[0]);
  paddle_release_param(params[1]);
H
Helin Wang 已提交
61

H
Helin Wang 已提交
62 63 64 65
  if (!paddle_save_model(c, "/tmp/")) {
    panic();
  }

66 67
  return 0;
}