mirror of
https://github.com/wassname/ray.git
synced 2026-09-09 11:32:43 +08:00
initial orchestra commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <grpc++/grpc++.h>
|
||||
|
||||
#include "orchestra.grpc.pb.h"
|
||||
#include "orchlib.h"
|
||||
|
||||
using grpc::Channel;
|
||||
using grpc::ClientContext;
|
||||
using grpc::Status;
|
||||
|
||||
class Client {
|
||||
public:
|
||||
Client(std::shared_ptr<Channel> channel)
|
||||
: stub_(Orchestra::NewStub(channel)) {}
|
||||
|
||||
void RemoteCall(const std::string& name) {
|
||||
RemoteCallRequest request;
|
||||
request.set_name(name);
|
||||
|
||||
RemoteCallReply reply;
|
||||
ClientContext context;
|
||||
|
||||
Status status = stub_->RemoteCall(&context, request, &reply);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<Orchestra::Stub> stub_;
|
||||
};
|
||||
|
||||
void* orch_create_context(const char* server_addr) {
|
||||
Client* client = new Client(grpc::CreateChannel("localhost:50052", grpc::InsecureChannelCredentials()));
|
||||
return client;
|
||||
}
|
||||
|
||||
size_t orch_remote_call(void* context, const char* name, void* args) {
|
||||
Client* client = (Client*)context;
|
||||
client->RemoteCall(std::string(name));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
Client greeter(
|
||||
grpc::CreateChannel("localhost:50052", grpc::InsecureChannelCredentials()));
|
||||
std::string user("world");
|
||||
greeter.RemoteCall(user);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
extern "C" {
|
||||
|
||||
void* orch_create_context(const char* server_addr);
|
||||
size_t orch_remote_call(void* context, const char* name, void* args);
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
from .context import Context
|
||||
@@ -0,0 +1,14 @@
|
||||
cdef extern void* orch_create_context(const char* server_addr);
|
||||
cdef extern size_t orch_remote_call(void* context, const char* name, void* args);
|
||||
|
||||
cdef class Context:
|
||||
cdef void* context
|
||||
|
||||
def __cinit__(self):
|
||||
self.context = NULL
|
||||
|
||||
def connect(self, server_addr):
|
||||
self.context = orch_create_context(server_addr)
|
||||
|
||||
def call(self, name):
|
||||
orch_remote_call(self.context, name, <void*>0)
|
||||
@@ -0,0 +1,16 @@
|
||||
from setuptools import setup, Extension, find_packages
|
||||
from Cython.Build import cythonize
|
||||
|
||||
# because of relative paths, this must be run from inside orch/lib/orchpy/
|
||||
|
||||
setup(
|
||||
name = "orchestra",
|
||||
version = "0.1.dev0",
|
||||
ext_modules = cythonize([
|
||||
Extension("orchpy/context",
|
||||
sources = ["orchpy/context.pyx"], libraries=["orchlib"],
|
||||
library_dirs=['../orchlib/'])],
|
||||
compiler_directives={'language_level': 3}),
|
||||
use_2to3=True,
|
||||
packages=find_packages()
|
||||
)
|
||||
Reference in New Issue
Block a user