-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
103 changed files
with
10,626 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,3 +193,6 @@ tags | |
# Persistent undo | ||
[._]*.un~ | ||
|
||
|
||
src/bin | ||
src/bazel** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7.4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
############################################################################### | ||
# Bazel now uses Bzlmod by default to manage external dependencies. | ||
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel. | ||
# | ||
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958 | ||
############################################################################### |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "com_github_grpc_grpc", | ||
strip_prefix = "grpc-tags-v1.63.0", | ||
urls = ["https://github.com/grpc/grpc/archive/tags/v1.63.0.tar.gz"], | ||
) | ||
|
||
http_archive( | ||
name = "com_github_singnet_das_proto", | ||
strip_prefix = "das-proto-0.1.13", | ||
urls = ["https://github.com/singnet/das-proto/archive/refs/tags/0.1.13.tar.gz"], | ||
) | ||
|
||
http_archive( | ||
name = "com_github_singnet_das_node", | ||
strip_prefix = "das-node-ab-test-1", | ||
urls = ["https://github.com/singnet/das-node/archive/refs/tags/ab-test-1.tar.gz"], | ||
) | ||
|
||
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps") | ||
grpc_deps() | ||
load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps") | ||
grpc_extra_deps() | ||
|
||
http_archive( | ||
name = "com_github_google_googletest", | ||
strip_prefix = "googletest-1.14.0", | ||
urls = ["https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz"] | ||
) | ||
|
||
new_local_repository( | ||
name = "mbedcrypto", | ||
path = "/opt/3rd-party/mbedcrypto", | ||
build_file_content = '\ | ||
cc_library(\ | ||
name = "lib",\ | ||
srcs = ["libmbedcrypto.a"],\ | ||
visibility = ["//visibility:public"],\ | ||
)\ | ||
' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
rm -f ../bin/* && ../scripts/bazel_build.sh && ../bin/attention_broker 37007 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
cc_binary( | ||
name = "attention_broker_service", | ||
srcs = [], | ||
defines = ["BAZEL_BUILD"], | ||
deps = [ | ||
"//cpp/main:attention_broker_main_lib", | ||
"//cpp/utils:utils_lib", | ||
"@com_github_singnet_das_proto//:attention_broker_cc_grpc", | ||
"@com_github_grpc_grpc//:grpc++", | ||
"@com_github_grpc_grpc//:grpc++_reflection", | ||
"@mbedcrypto//:lib", | ||
], | ||
linkstatic = 1 | ||
) | ||
|
||
cc_binary( | ||
name = "query_broker", | ||
srcs = [], | ||
defines = ["BAZEL_BUILD"], | ||
deps = [ | ||
"//cpp/main:query_engine_main_lib", | ||
"//cpp/utils:utils_lib", | ||
"@mbedcrypto//:lib", | ||
], | ||
linkstatic = 1 | ||
) | ||
|
||
cc_binary( | ||
name = "query", | ||
srcs = [], | ||
defines = ["BAZEL_BUILD"], | ||
deps = [ | ||
"//cpp/main:query_client_main_lib", | ||
"//cpp/utils:utils_lib", | ||
"@mbedcrypto//:lib", | ||
], | ||
linkstatic = 1 | ||
) | ||
|
||
cc_binary( | ||
name = "link_creation_engine", | ||
srcs = [], | ||
defines = ["BAZEL_BUILD"], | ||
deps = [ | ||
"//cpp/main:link_creation_engine_main_lib", | ||
"//cpp/utils:utils_lib", | ||
"@mbedcrypto//:lib", | ||
], | ||
linkstatic = 1 | ||
) | ||
|
||
cc_binary( | ||
name = "word_query", | ||
srcs = [], | ||
defines = ["BAZEL_BUILD"], | ||
deps = [ | ||
"//cpp/main:word_query_main_lib", | ||
"//cpp/utils:utils_lib", | ||
"@mbedcrypto//:lib", | ||
], | ||
linkstatic = 1 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
#include "RequestSelector.h" | ||
#include "AttentionBrokerServer.h" | ||
|
||
using namespace attention_broker_server; | ||
|
||
const double AttentionBrokerServer::RENT_RATE; | ||
const double AttentionBrokerServer::SPREADING_RATE_LOWERBOUND; | ||
const double AttentionBrokerServer::SPREADING_RATE_UPPERBOUND; | ||
|
||
// -------------------------------------------------------------------------------- | ||
// Public methods | ||
|
||
AttentionBrokerServer::AttentionBrokerServer() { | ||
this->global_context = "global"; | ||
this->stimulus_requests = new SharedQueue(); | ||
this->correlation_requests = new SharedQueue(); | ||
this->worker_threads = new WorkerThreads(stimulus_requests, correlation_requests); | ||
HebbianNetwork *network = new HebbianNetwork(); | ||
this->hebbian_network[this->global_context] = network; | ||
this->updater = HebbianNetworkUpdater::factory(HebbianNetworkUpdaterType::EXACT_COUNT); | ||
this->stimulus_spreader = StimulusSpreader::factory(StimulusSpreaderType::TOKEN); | ||
|
||
} | ||
|
||
AttentionBrokerServer::~AttentionBrokerServer() { | ||
graceful_shutdown(); | ||
delete this->worker_threads; | ||
delete this->stimulus_requests; | ||
delete this->correlation_requests; | ||
delete this->updater; | ||
delete this->stimulus_spreader; | ||
for (auto pair:this->hebbian_network) { | ||
delete pair.second; | ||
} | ||
} | ||
|
||
void AttentionBrokerServer::graceful_shutdown() { | ||
this->rpc_api_enabled = false; | ||
this->worker_threads->graceful_stop(); | ||
} | ||
|
||
// RPC API | ||
|
||
Status AttentionBrokerServer::ping(ServerContext* grpc_context, const dasproto::Empty *request, dasproto::Ack* reply) { | ||
reply->set_msg("PING"); | ||
if (rpc_api_enabled) { | ||
return Status::OK; | ||
} else{ | ||
return Status::CANCELLED; | ||
} | ||
} | ||
|
||
Status AttentionBrokerServer::stimulate(ServerContext* grpc_context, const dasproto::HandleCount *request, dasproto::Ack* reply) { | ||
#ifdef DEBUG | ||
cout << "AttentionBrokerServer::stimulate() BEGIN" << endl; | ||
cout << "Context: " << request->context() << endl; | ||
#endif | ||
if (request->map_size() > 0) { | ||
HebbianNetwork *network = select_hebbian_network(request->context()); | ||
((dasproto::HandleCount *) request)->set_hebbian_network((long) network); | ||
//this->stimulus_requests->enqueue((void *) request); | ||
this->stimulus_spreader->spread_stimuli(request); | ||
} | ||
reply->set_msg("STIMULATE"); | ||
#ifdef DEBUG | ||
cout << "AttentionBrokerServer::stimulate() END" << endl; | ||
#endif | ||
if (rpc_api_enabled) { | ||
return Status::OK; | ||
} else{ | ||
return Status::CANCELLED; | ||
} | ||
} | ||
|
||
Status AttentionBrokerServer::correlate(ServerContext* grpc_context, const dasproto::HandleList *request, dasproto::Ack* reply) { | ||
#ifdef DEBUG | ||
cout << "AttentionBrokerServer::correlate() BEGIN" << endl; | ||
cout << "Context: " << request->context() << endl; | ||
#endif | ||
if (request->list_size() > 0) { | ||
HebbianNetwork *network = select_hebbian_network(request->context()); | ||
((dasproto::HandleList *) request)->set_hebbian_network((long) network); | ||
//this->correlation_requests->enqueue((void *) request); | ||
this->updater->correlation(request); | ||
} | ||
reply->set_msg("CORRELATE"); | ||
#ifdef DEBUG | ||
cout << "AttentionBrokerServer::correlate() END" << endl; | ||
#endif | ||
if (rpc_api_enabled) { | ||
return Status::OK; | ||
} else { | ||
return Status::CANCELLED; | ||
} | ||
} | ||
|
||
Status AttentionBrokerServer::get_importance(ServerContext *grpc_context, const dasproto::HandleList *request, dasproto::ImportanceList *reply) { | ||
#ifdef DEBUG | ||
cout << "AttentionBrokerServer::get_importance() BEGIN" << endl; | ||
cout << "Context: " << request->context() << endl; | ||
#endif | ||
if (this->rpc_api_enabled) { | ||
int num_handles = request->list_size(); | ||
if (num_handles > 0) { | ||
HebbianNetwork *network = select_hebbian_network(request->context()); | ||
for (int i = 0; i < num_handles; i++) { | ||
float importance = network->get_node_importance(request->list(i)); | ||
reply->add_list(importance); | ||
} | ||
} | ||
#ifdef DEBUG | ||
cout << "AttentionBrokerServer::get_importance() END" << endl; | ||
#endif | ||
return Status::OK; | ||
} else { | ||
return Status::CANCELLED; | ||
} | ||
} | ||
|
||
// -------------------------------------------------------------------------------- | ||
// Private methods | ||
// | ||
|
||
HebbianNetwork *AttentionBrokerServer::select_hebbian_network(const string &context) { | ||
HebbianNetwork *network; | ||
if ((context != "") && (this->hebbian_network.find(context) != this->hebbian_network.end())) { | ||
network = this->hebbian_network[context]; | ||
} | ||
if (context == "") { | ||
network = this->hebbian_network[this->global_context]; | ||
} else { | ||
if (this->hebbian_network.find(context) == this->hebbian_network.end()) { | ||
network = new HebbianNetwork(); | ||
this->hebbian_network[context] = network; | ||
} else { | ||
network = this->hebbian_network[context]; | ||
} | ||
} | ||
return network; | ||
} |
Oops, something went wrong.