Skip to content

Commit 66de965

Browse files
0mpapaszke
authored andcommitted
Replace ZeroMQ (pytorch#41)
1 parent 10d32fb commit 66de965

File tree

8 files changed

+350
-205
lines changed

8 files changed

+350
-205
lines changed

torch/lib/THD/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Dependecies
2+
3+
- Asio C++ Library
4+
5+
## macOS
6+
7+
```
8+
brew install asio
9+
```

torch/lib/THD/master_worker/common/ByteArray.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ std::size_t ByteArray::length() const {
6969
return _length;
7070
}
7171

72+
std::string ByteArray::to_string() {
73+
return std::string(_data, _length);
74+
}
75+
7276
ByteArray ByteArray::fromData(const char* arr, std::size_t size) {
7377
char* new_arr = static_cast<char*>(std::malloc(size));
7478
if (new_arr == nullptr) {

torch/lib/THD/master_worker/common/ByteArray.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#pragma once
22

33
#include <cstddef>
4+
#include <string>
45

56
namespace thd { namespace rpc {
67

78
struct ByteArray {
9+
using size_type = std::size_t;
810
ByteArray();
911
ByteArray(std::size_t size);
1012
ByteArray(char* arr, std::size_t size);
@@ -14,14 +16,16 @@ struct ByteArray {
1416

1517
ByteArray& append(const char* arr, std::size_t size);
1618
char* data() const;
17-
std::size_t length() const;
19+
size_type length() const;
20+
21+
std::string to_string();
1822

1923
static ByteArray fromData(const char* arr, std::size_t size);
2024

2125
private:
2226
char* _data;
23-
std::size_t _length; // The length of the data.
24-
std::size_t _size; // The size of the allocated memory.
27+
size_type _length; // The length of the data.
28+
size_type _size; // The size of the allocated memory.
2529

2630
void _realloc(std::size_t new_size);
2731
void _resize(std::size_t desired_size);

0 commit comments

Comments
 (0)