Skip to content

Commit

Permalink
grpc: save progress on grpc-gateway integration
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Whisonant <tim.whisonant@intel.com>
  • Loading branch information
tswhison committed May 11, 2023
1 parent 3d5db60 commit e72562b
Show file tree
Hide file tree
Showing 9 changed files with 707 additions and 31 deletions.
9 changes: 8 additions & 1 deletion libraries/libopae-clisrv/grpc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,14 @@ fpga_result OPAEClient::fpgaPrepareBuffer(const fpga_remote_id &handle_id,

fpga_result res = to_opae_fpga_result[reply.result()];

if (res == FPGA_OK) buf_id = to_opae_fpga_remote_id(reply.buf_id());
if (res == FPGA_OK) {
// Special case: when flags contains FPGA_BUF_PREALLOCATED,
// and when buf_addr and length are nullptr and 0, then an FPGA_OK
// indicates that the API supports preallocated buffers.
if ((flags & FPGA_BUF_PREALLOCATED) && !buf_addr && !length) return FPGA_OK;

buf_id = to_opae_fpga_remote_id(reply.buf_id());
}

return res;
}
Expand Down
105 changes: 90 additions & 15 deletions libraries/libopae-clisrv/proto/opae_gw.proto
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,24 @@ service OPAEService {
body: "*"
};
}
rpc fpgaCloneToken(CloneTokenRequest) returns (CloneTokenReply) {}
rpc fpgaGetProperties(GetPropertiesRequest) returns (GetPropertiesReply) {}
rpc fpgaUpdateProperties(UpdatePropertiesRequest) returns (UpdatePropertiesReply) {}
rpc fpgaCloneToken(CloneTokenRequest) returns (CloneTokenReply) {
option (google.api.http) = {
post: "/fpga/v1/token/clone"
body: "*"
};
}
rpc fpgaGetProperties(GetPropertiesRequest) returns (GetPropertiesReply) {
option (google.api.http) = {
post: "/fpga/v1/token/properties/get"
body: "*"
};
}
rpc fpgaUpdateProperties(UpdatePropertiesRequest) returns (UpdatePropertiesReply) {
option (google.api.http) = {
post: "/fpga/v1/token/properties/update"
body: "*"
};
}
rpc fpgaOpen(OpenRequest) returns (OpenReply) {
option (google.api.http) = {
post: "/fpga/v1/token/open"
Expand All @@ -236,18 +251,78 @@ service OPAEService {
body: "*"
};
}
rpc fpgaReset(ResetRequest) returns (ResetReply) {}
rpc fpgaGetPropertiesFromHandle(GetPropertiesFromHandleRequest) returns (GetPropertiesFromHandleReply) {}
rpc fpgaMapMMIO(MapMMIORequest) returns (MapMMIOReply) {}
rpc fpgaUnmapMMIO(UnmapMMIORequest) returns (UnmapMMIOReply) {}
rpc fpgaReadMMIO32(ReadMMIO32Request) returns (ReadMMIO32Reply) {}
rpc fpgaWriteMMIO32(WriteMMIO32Request) returns (WriteMMIO32Reply) {}
rpc fpgaReadMMIO64(ReadMMIO64Request) returns (ReadMMIO64Reply) {}
rpc fpgaWriteMMIO64(WriteMMIO64Request) returns (WriteMMIO64Reply) {}
rpc fpgaWriteMMIO512(WriteMMIO512Request) returns (WriteMMIO512Reply) {}
rpc fpgaPrepareBuffer(PrepareBufferRequest) returns (PrepareBufferReply) {}
rpc fpgaReleaseBuffer(ReleaseBufferRequest) returns (ReleaseBufferReply) {}
rpc fpgaGetIOAddress(GetIOAddressRequest) returns (GetIOAddressReply) {}
rpc fpgaReset(ResetRequest) returns (ResetReply) {
option (google.api.http) = {
post: "/fpga/v1/afu/reset"
body: "*"
};
}
rpc fpgaGetPropertiesFromHandle(GetPropertiesFromHandleRequest) returns (GetPropertiesFromHandleReply) {
option (google.api.http) = {
post: "/fpga/v1/handle/properties/get"
body: "*"
};
}
rpc fpgaMapMMIO(MapMMIORequest) returns (MapMMIOReply) {
option (google.api.http) = {
post: "/fpga/v1/handle/mmio/map"
body: "*"
};
}
rpc fpgaUnmapMMIO(UnmapMMIORequest) returns (UnmapMMIOReply) {
option (google.api.http) = {
post: "/fpga/v1/handle/mmio/unmap"
body: "*"
};
}
rpc fpgaReadMMIO32(ReadMMIO32Request) returns (ReadMMIO32Reply) {
option (google.api.http) = {
post: "/fpga/v1/handle/mmio/read32"
body: "*"
};
}
rpc fpgaWriteMMIO32(WriteMMIO32Request) returns (WriteMMIO32Reply) {
option (google.api.http) = {
post: "/fpga/v1/handle/mmio/write32"
body: "*"
};
}
rpc fpgaReadMMIO64(ReadMMIO64Request) returns (ReadMMIO64Reply) {
option (google.api.http) = {
post: "/fpga/v1/handle/mmio/read64"
body: "*"
};
}
rpc fpgaWriteMMIO64(WriteMMIO64Request) returns (WriteMMIO64Reply) {
option (google.api.http) = {
post: "/fpga/v1/handle/mmio/write64"
body: "*"
};
}
rpc fpgaWriteMMIO512(WriteMMIO512Request) returns (WriteMMIO512Reply) {
option (google.api.http) = {
post: "/fpga/v1/handle/mmio/write512"
body: "*"
};
}
rpc fpgaPrepareBuffer(PrepareBufferRequest) returns (PrepareBufferReply) {
option (google.api.http) = {
post: "/fpga/v1/handle/buffers/prepare"
body: "*"
};
}
rpc fpgaReleaseBuffer(ReleaseBufferRequest) returns (ReleaseBufferReply) {
option (google.api.http) = {
post: "/fpga/v1/handle/buffers/release"
body: "*"
};
}
rpc fpgaGetIOAddress(GetIOAddressRequest) returns (GetIOAddressReply) {
option (google.api.http) = {
post: "/fpga/v1/handle/buffers/ioaddress"
body: "*"
};
}
rpc fpgaReadError(ReadErrorRequest) returns (ReadErrorReply) {}
rpc fpgaGetErrorInfo(GetErrorInfoRequest) returns (GetErrorInfoReply) {}
rpc fpgaClearError(ClearErrorRequest) returns (ClearErrorReply) {}
Expand Down
51 changes: 51 additions & 0 deletions python/opae.http/opae/http/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,53 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

# fpga_result
FPGA_OK = 0
FPGA_INVALID_PARAM = 1
FPGA_BUSY = 2
FPGA_EXCEPTION = 3
FPGA_NOT_FOUND = 4
FPGA_NO_MEMORY = 5
FPGA_NOT_SUPPORTED = 6
FPGA_NO_DRIVER = 7
FPGA_NO_DAEMON = 8
FPGA_NO_ACCESS = 9
FPGA_RECONF_ERROR = 10

def fpga_result_to_str(r):
d = {FPGA_OK: 'FPGA_OK',
FPGA_INVALID_PARAM: 'FPGA_INVALID_PARAM',
FPGA_BUSY: 'FPGA_BUSY',
FPGA_EXCEPTION: 'FPGA_EXCEPTION',
FPGA_NOT_FOUND: 'FPGA_NOT_FOUND',
FPGA_NO_MEMORY: 'FPGA_NO_MEMORY',
FPGA_NOT_SUPPORTED: 'FPGA_NOT_SUPPORTED',
FPGA_NO_DRIVER: 'FPGA_NO_DRIVER',
FPGA_NO_DAEMON: 'FPGA_NO_DAEMON',
FPGA_NO_ACCESS: 'FPGA_NO_ACCESS',
FPGA_RECONF_ERROR: 'FPGA_RECONF_ERROR'}
return d[r]

def fpga_result_from_str(s):
d = {'FPGA_OK': FPGA_OK,
'FPGA_INVALID_PARAM': FPGA_INVALID_PARAM,
'FPGA_BUSY': FPGA_BUSY,
'FPGA_EXCEPTION': FPGA_EXCEPTION,
'FPGA_NOT_FOUND': FPGA_NOT_FOUND,
'FPGA_NO_MEMORY': FPGA_NO_MEMORY,
'FPGA_NOT_SUPPORTED': FPGA_NOT_SUPPORTED,
'FPGA_NO_DRIVER': FPGA_NO_DRIVER,
'FPGA_NO_DAEMON': FPGA_NO_DAEMON,
'FPGA_NO_ACCESS': FPGA_NO_ACCESS,
'FPGA_RECONF_ERROR': FPGA_RECONF_ERROR}
return d[s]

def raise_for_error(result, msg):
res = fpga_result_from_str(result) if type(result) is str else result
s = fpga_result_to_str(result) if type(result) is int else result
if res != FPGA_OK:
raise RuntimeError(f'{msg} {s}')

# fpga_objtype
FPGA_DEVICE = 0
FPGA_ACCELERATOR = 1
Expand Down Expand Up @@ -76,3 +123,7 @@ def fpga_accelerator_state_from_str(s):
# fpga_open_flags
FPGA_OPEN_SHARED = 1

# fpga_buffer_flags
FPGA_BUF_PREALLOCATED = 1
FPGA_BUF_QUIET = 2
FPGA_BUF_READ_ONLY = 4
6 changes: 4 additions & 2 deletions python/opae.http/opae/http/enumerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

import os
import requests

import opae.http.constants as constants
Expand All @@ -52,7 +51,7 @@ def enumerate(url, filters, max_tokens):
'max_tokens': max_tokens,
}

enum_url = os.path.join(url, 'fpga/v1/enumerate')
enum_url = url + '/fpga/v1/enumerate'
print(enum_url)

tokens = []
Expand All @@ -61,6 +60,9 @@ def enumerate(url, filters, max_tokens):
resp.raise_for_status()

jobj = resp.json()

constants.raise_for_error(jobj['result'], 'fpgaEnumerate returned')

for tok in jobj['tokens']:
tokens.append(token.from_json_obj(tok))

Expand Down
Loading

0 comments on commit e72562b

Please sign in to comment.