pytorch

Форк
0
/
zmq_feeder.cc 
63 строки · 2.1 Кб
1
/**
2
 * Copyright (c) 2016-present, Facebook, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
// This binary provides an easy way to open a zeromq server and feeds data to
18
// clients connect to it. It uses the Caffe2 db as the backend, thus allowing
19
// one to convert any db-compliant storage to a zeromq service.
20

21
#include "caffe2/core/db.h"
22
#include "caffe2/core/init.h"
23
#include "caffe2/core/logging.h"
24
#include "caffe2/utils/zmq_helper.h"
25

26
C10_DEFINE_string(server, "tcp://*:5555", "The server address.");
27
C10_DEFINE_string(input_db, "", "The input db.");
28
C10_DEFINE_string(input_db_type, "", "The input db type.");
29

30

31
int main(int argc, char** argv) {
32
  caffe2::GlobalInit(&argc, &argv);
33

34
  LOG(INFO) << "Opening DB...";
35
  auto in_db = caffe2::db::CreateDB(
36
      FLAGS_input_db_type, FLAGS_input_db, caffe2::db::READ);
37
  CAFFE_ENFORCE(
38
      in_db,
39
      "Cannot load input db " + FLAGS_input_db + " of expected type " +
40
          FLAGS_input_db_type);
41
  auto cursor = in_db->NewCursor();
42
  LOG(INFO) << "DB opened.";
43

44
  LOG(INFO) << "Starting ZeroMQ server...";
45

46
  //  Socket to talk to clients
47
  caffe2::ZmqSocket sender(ZMQ_PUSH);
48
  sender.Bind(FLAGS_server);
49
  LOG(INFO) << "Server created at " << FLAGS_server;
50

51
  while (1) {
52
    VLOG(1) << "Sending " << cursor->key();
53
    sender.SendTillSuccess(cursor->key(), ZMQ_SNDMORE);
54
    sender.SendTillSuccess(cursor->value(), 0);
55
    cursor->Next();
56
    if (!cursor->Valid()) {
57
      cursor->SeekToFirst();
58
    }
59
  }
60
  // We do not do an elegant quit since this binary is going to be terminated by
61
  // control+C.
62
  return 0;
63
}
64

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.