Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ COPTS = [
}) + select({
"//bazel/config:brpc_with_rdma": ["-DBRPC_WITH_RDMA=1"],
"//conditions:default": [""],
}) + select({
"//bazel/config:brpc_with_gdr": ["-DBRPC_WITH_gdr=1"],
"//conditions:default": [""],
}) + select({
"//bazel/config:brpc_with_debug_bthread_sche_safety": ["-DBRPC_DEBUG_BTHREAD_SCHE_SAFETY=1"],
"//conditions:default": ["-DBRPC_DEBUG_BTHREAD_SCHE_SAFETY=0"],
Expand Down Expand Up @@ -91,6 +94,11 @@ LINKOPTS = [
"-libverbs",
],
"//conditions:default": [],
}) + select({
"//bazel/config:brpc_with_gdr": [
"-lcuda -lcudart",
],
"//conditions:default": [],
}) + select({
"//bazel/config:brpc_with_asan": ["-fsanitize=address"],
"//conditions:default": [""],
Expand Down Expand Up @@ -232,6 +240,7 @@ BUTIL_SRCS = [
"src/butil/iobuf.cpp",
"src/butil/single_iobuf.cpp",
"src/butil/iobuf_profiler.cpp",
"src/butil/gpu/gpu_block_pool.cpp",
"src/butil/binary_printer.cpp",
"src/butil/recordio.cc",
"src/butil/popen.cpp",
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ BUTIL_SOURCES = \
src/butil/files/scoped_temp_dir.cc \
src/butil/file_util.cc \
src/butil/file_util_posix.cc \
src/butil/gpu/gpu_block_pool.cpp \
src/butil/guid.cc \
src/butil/guid_posix.cc \
src/butil/hash.cc \
Expand Down
8 changes: 7 additions & 1 deletion bazel/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ config_setting(
visibility = ["//visibility:public"],
)

config_setting(
name = "brpc_with_gdr",
define_values = {"BRPC_WITH_GDR": "true"},
visibility = ["//visibility:public"],
)

config_setting(
name = "brpc_with_boringssl",
define_values = {"BRPC_WITH_BORINGSSL": "true"},
Expand Down Expand Up @@ -148,4 +154,4 @@ config_setting(
name = "with_babylon_counter",
define_values = {"with_babylon_counter": "true"},
visibility = ["//visibility:public"],
)
)
17 changes: 16 additions & 1 deletion config_brpc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ else
LDD=ldd
fi

TEMP=`getopt -o v: --long headers:,libs:,cc:,cxx:,with-glog,with-thrift,with-rdma,with-mesalink,with-bthread-tracer,with-debug-bthread-sche-safety,with-debug-lock,with-asan,nodebugsymbols,werror -n 'config_brpc' -- "$@"`
TEMP=`getopt -o v: --long headers:,libs:,cc:,cxx:,with-glog,with-thrift,with-rdma,with-gdr,with-mesalink,with-bthread-tracer,with-debug-bthread-sche-safety,with-debug-lock,with-asan,nodebugsymbols,werror -n 'config_brpc' -- "$@"`
WITH_GLOG=0
WITH_THRIFT=0
WITH_RDMA=0
WITH_GDR=0
WITH_MESALINK=0
WITH_BTHREAD_TRACER=0
WITH_ASAN=0
Expand Down Expand Up @@ -87,6 +88,7 @@ while true; do
--with-glog ) WITH_GLOG=1; shift 1 ;;
--with-thrift) WITH_THRIFT=1; shift 1 ;;
--with-rdma) WITH_RDMA=1; shift 1 ;;
--with-gdr) WITH_GDR=1; shift 1 ;;
--with-mesalink) WITH_MESALINK=1; shift 1 ;;
--with-bthread-tracer) WITH_BTHREAD_TRACER=1; shift 1 ;;
--with-debug-bthread-sche-safety ) BRPC_DEBUG_BTHREAD_SCHE_SAFETY=1; shift 1 ;;
Expand Down Expand Up @@ -532,6 +534,18 @@ if [ $WITH_RDMA != 0 ]; then
append_to_output "WITH_RDMA=1"
fi

if [ $WITH_GDR != 0 ]; then
CUDA_LIB="/usr/local/cuda/lib64"
CUDA_HDR="/usr/local/cuda/include"
append_to_output_libs "$CUDA_LIB"
append_to_output_headers "$CUDA_HDR"

CPPFLAGS="${CPPFLAGS} -DBRPC_WITH_GDR"

append_to_output "DYNAMIC_LINKINGS+=-lcuda -lcudart"
append_to_output "WITH_GDR=1"
fi

if [ $WITH_MESALINK != 0 ]; then
CPPFLAGS="${CPPFLAGS} -DUSE_MESALINK"
fi
Expand Down Expand Up @@ -652,6 +666,7 @@ print_info "System: $SYSTEM"
if [ $WITH_GLOG -ne 0 ]; then print_info "With glog: yes"; fi
if [ $WITH_THRIFT -ne 0 ]; then print_info "With thrift: yes"; fi
if [ $WITH_RDMA -ne 0 ]; then print_info "With RDMA: yes"; fi
if [ $WITH_GDR -ne 0 ]; then print_info "With GDR: yes"; fi
if [ $WITH_MESALINK -ne 0 ]; then print_info "With MesaLink: yes"; fi
if [ $WITH_BTHREAD_TRACER -ne 0 ]; then print_info "With bthread tracer: yes"; fi
if [ $WITH_ASAN -ne 0 ]; then print_info "With ASAN: yes"; fi
Expand Down
5 changes: 4 additions & 1 deletion example/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ COPTS = [
}) + select({
"//bazel/config:brpc_with_rdma": ["-DBRPC_WITH_RDMA=1"],
"//conditions:default": [""],
}) + select({
"//bazel/config:brpc_with_gdr": ["-DBRPC_WITH_GDR=1"],
"//conditions:default": [""],
})

proto_library(
Expand Down Expand Up @@ -133,4 +136,4 @@ cc_binary(
deps = [
"//:brpc",
],
)
)
59 changes: 55 additions & 4 deletions example/rdma_performance/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
// specific language governing permissions and limitations
// under the License.

#ifdef BRPC_WITH_GDR
#include <cuda.h>
#include <cuda_runtime.h>
#endif
#include <stdlib.h>
#include <unistd.h>
#include <vector>
Expand Down Expand Up @@ -42,6 +46,7 @@ DEFINE_string(connection_type, "single", "Connection type of the channel");
DEFINE_string(protocol, "baidu_std", "Protocol type.");
DEFINE_string(servers, "0.0.0.0:8002+0.0.0.0:8002", "IP Address of servers");
DEFINE_bool(use_rdma, true, "Use RDMA or not");
DEFINE_bool(use_gdr, false, "Use GDR or not");
DEFINE_int32(rpc_timeout_ms, 2000, "RPC call timeout");
DEFINE_int32(test_seconds, 20, "Test running time");
DEFINE_int32(test_iterations, 0, "Test iterations");
Expand Down Expand Up @@ -84,16 +89,47 @@ class PerformanceTest {
, _stop(false)
{
if (attachment_size > 0) {
_addr = malloc(attachment_size);
butil::fast_rand_bytes(_addr, attachment_size);
_attachment.append(_addr, attachment_size);
#ifdef BRPC_WITH_GDR
if (FLAGS_use_gdr) {
int gpu_id = 0;
cudaSetDevice(gpu_id);
cudaMalloc(&_addr, attachment_size);
auto pd = brpc::rdma::GetRdmaPd();
mr = ibv_reg_mr(pd, _addr, attachment_size,
IBV_ACCESS_LOCAL_WRITE |
IBV_ACCESS_LOCAL_READ |
IBV_ACCESS_REMOTE_WRITE |
);
if (!mr) {
LOG(FATAL) << "Failed to register MR:" << strerror(errno)
<< ", addr:" << _addr;
}
auto deleter = [](void* data) {};
_attachment.append_user_data_with_meta(_addr, attachment_size, deleter, mr->lkey);
}
else
#endif
{
_addr = malloc(attachment_size);
butil::fast_rand_bytes(_addr, attachment_size);
_attachment.append(_addr, attachment_size);
}
}
_echo_attachment = echo_attachment;
}

~PerformanceTest() {
if (_addr) {
free(_addr);
#ifdef BRPC_WITH_GDR
if (FLAGS_use_gdr) {
ibv_dereg_mr(mr);
cudaFree(_addr);
}
else
#endif
{
free(_addr);
}
}
delete _channel;
}
Expand All @@ -103,6 +139,11 @@ class PerformanceTest {
int Init() {
brpc::ChannelOptions options;
options.socket_mode = FLAGS_use_rdma? brpc::SOCKET_MODE_RDMA : brpc::SOCKET_MODE_TCP;
#ifdef BRPC_WITH_GDR
if (FLAGS_use_gdr) {
options.socket_mode = brpc::SOCKET_MODE_GDR;
}
#endif
options.protocol = FLAGS_protocol;
options.connection_type = FLAGS_connection_type;
options.timeout_ms = FLAGS_rpc_timeout_ms;
Expand Down Expand Up @@ -203,6 +244,9 @@ class PerformanceTest {
}

private:
#ifdef BRPC_WITH_GDR
ibv_mr* mr;
#endif
void* _addr;
brpc::Channel* _channel;
uint64_t _start_time;
Expand All @@ -223,6 +267,7 @@ void Test(int thread_num, int attachment_size) {
<< ", Depth: " << FLAGS_queue_depth
<< ", Attachment: " << attachment_size << "B"
<< ", RDMA: " << (FLAGS_use_rdma ? "yes" : "no")
<< ", GDR: " << (FLAGS_use_gdr ? "yes" : "no")
<< ", Echo: " << (FLAGS_echo_attachment ? "yes]" : "no]")
<< std::endl;
g_total_bytes.store(0, butil::memory_order_relaxed);
Expand Down Expand Up @@ -278,6 +323,12 @@ int main(int argc, char* argv[]) {
if (FLAGS_use_rdma) {
brpc::rdma::GlobalRdmaInitializeOrDie();
}
#ifdef BRPC_WITH_GDR
else if (FLAGS_use_gdr) {
brpc::rdma::GlobalRdmaInitializeOrDie();
brpc::rdma::GlobalGdrInitializeOrDie();
}
#endif

brpc::StartDummyServerAt(FLAGS_dummy_port);

Expand Down
7 changes: 7 additions & 0 deletions example/rdma_performance/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

DEFINE_int32(port, 8002, "TCP Port of this server");
DEFINE_bool(use_rdma, true, "Use RDMA or not");
DEFINE_bool(use_gdr, false, "Use RDMA or not");

butil::atomic<uint64_t> g_last_time(0);

Expand Down Expand Up @@ -77,6 +78,12 @@ int main(int argc, char* argv[]) {

brpc::ServerOptions options;
options.socket_mode = FLAGS_use_rdma? brpc::SOCKET_MODE_RDMA : brpc::SOCKET_MODE_TCP;
#ifdef BRPC_WITH_GDR
if (FLAGS_use_gdr) {
options.socket_mode = brpc::SOCKET_MODE_GDR;
}
#endif

if (server.Start(FLAGS_port, &options) != 0) {
LOG(ERROR) << "Fail to start EchoServer";
return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/brpc/acceptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ friend class Server;
bool _force_ssl;
std::shared_ptr<SocketSSLContext> _ssl_ctx;

// Choose to use a certain socket: 0 TCP, 1 RDMA
// Choose to use a certain socket: 0 TCP, 1 RDMA, 2 GDR
SocketMode _socket_mode;

// Acceptor belongs to this tag
Expand Down
2 changes: 2 additions & 0 deletions src/brpc/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ static ChannelSignature ComputeChannelSignature(const ChannelOptions& opt) {
}
if (opt.socket_mode == SOCKET_MODE_RDMA) {
buf.append("|rdma");
} else if (opt.socket_mode == SOCKET_MODE_GDR) {
buf.append("|gdr");
}
butil::MurmurHash3_x64_128_Update(&mm_ctx, buf.data(), buf.size());
buf.clear();
Expand Down
35 changes: 35 additions & 0 deletions src/brpc/gdr_transport.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#if BRPC_WITH_GDR

#include "brpc/gdr_transport.h"
#include "brpc/rdma/rdma_helper.h"

namespace brpc {

void GdrTransport::Init(Socket *socket, const SocketOptions &options) {
DoInit(socket, options, true);
}

int GdrTransport::GdrContextInitOrDie() {
rdma::GlobalGdrInitializeOrDie();
return 0;
}

} // namespace brpc
#endif
32 changes: 32 additions & 0 deletions src/brpc/gdr_transport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#ifndef BRPC_GDR_TRANSPORT_H
#define BRPC_GDR_TRANSPORT_H

#if BRPC_WITH_GDR
#include "brpc/rdma_transport.h"

namespace brpc {
class GdrTransport : public RdmaTransport {
public:
void Init(Socket* socket, const SocketOptions& options) override;
static int GdrContextInitOrDie();
};
} // namespace brpc
#endif // BRPC_WITH_GDR
#endif //BRPC_GDR_TRANSPORT_H
Loading
Loading