Skip to content

Commit

Permalink
remove debugging prints
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiyueXu77 committed Apr 1, 2024
1 parent f223df7 commit d881d84
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 97 deletions.
20 changes: 6 additions & 14 deletions src/collective/aggregator.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,8 @@ void ApplyWithLabels(Context const*, MetaInfo const& info, HostDeviceVector<T>*
if (info.IsSecure() && is_gpair) {
// Under secure mode, gpairs will be processed to vector and encrypt
// information only available on rank 0

std::size_t buffer_size{};
std::int8_t *buffer;
//common::Span<std::int8_t> buffer;
if (collective::GetRank() == 0) {
std::vector<double> vector_gh;
for (std::size_t i = 0; i < size; i++) {
Expand All @@ -115,24 +113,18 @@ void ApplyWithLabels(Context const*, MetaInfo const& info, HostDeviceVector<T>*
vector_gh.push_back(gpair_ptr[1]);
}
// provide the vectors to the processor interface
// print vector size for rank 1
if (collective::GetRank() == 0) {
std::cout << "-----------Call Interface for gp encryption and broadcast"
<< ", size of gpairs: " << vector_gh.size()
<< " ----------------------" << std::endl;
auto buf = processor_instance->ProcessGHPairs(vector_gh);
buffer_size = buf.size();
buffer = reinterpret_cast<std::int8_t *>(buf.data());
std::cout << "buffer size: " << buffer_size << std::endl;
}
auto buf = processor_instance->ProcessGHPairs(vector_gh);
buffer_size = buf.size();
buffer = reinterpret_cast<std::int8_t *>(buf.data());
}
// broadcast the buffer size
collective::Broadcast(&buffer_size, sizeof(std::size_t), 0);

// broadcast the buffer size for other ranks to prepare
collective::Broadcast(&buffer_size, sizeof(std::size_t), 0);
// prepare buffer on passive parties for satisfying broadcast mpi call
if (collective::GetRank() != 0) {
buffer = reinterpret_cast<std::int8_t *>(malloc(buffer_size));
}

// broadcast the data buffer holding processed gpairs
collective::Broadcast(buffer, buffer_size, 0);

Expand Down
7 changes: 0 additions & 7 deletions src/learner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,20 +493,13 @@ class LearnerConfiguration : public Learner {

this->ConfigureMetrics(args);

if ((collective::GetRank() == 0)) {
std::cout << "Initialize interface" << std::endl;
}

xgboost::processing::ProcessorLoader loader;
processor_instance = loader.load("dummy");
if (collective::GetRank() == 0) {
processor_instance->Initialize(true, {});
} else {
processor_instance->Initialize(false, {});
}
//processor_instance->FreeBuffer(buf);
//processor_instance->Shutdown();
//loader.unload();

this->need_configuration_ = false;
if (ctx_.validate_parameters) {
Expand Down
78 changes: 2 additions & 76 deletions src/tree/hist/histogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,49 +77,9 @@ class HistogramBuilder {
std::vector<bst_node_t> const &nodes_to_build,
common::RowSetCollection const &row_set_collection,
common::Span<GradientPair const> gpair_h, bool force_read_by_column) {
// Print out all kinds if information for interface integration
if (is_distributed_ && is_col_split_ && is_secure_ && (collective::GetRank() == 0)) {
std::cout << "--------------Node Hist----------------" << std::endl;
std::cout << "Current samples on nodes: " << std::endl;
// print info on all nodes
for (std::size_t nid = 0; nid < row_set_collection.Size(); ++nid) {
auto size = row_set_collection[nid].Size();
std::cout << "Node " << nid << " has " << size << " rows." << std::endl;
// print the first and last indexes of the rows with iterator
if (size > 0) {
std::cout << "First index for node " << nid << " is "
<< *row_set_collection[nid].begin << " and last index is "
<< *(row_set_collection[nid].end - 1) << std::endl;
}
}
// print info on the nodes to build
for (auto nit = nodes_to_build.begin(); nit != nodes_to_build.end(); ++nit) {
std::cout << "Building local histogram for node ID: " << *nit
<< " with " << row_set_collection[*nit].Size()
<< " samples." << std::endl;
}
std::cout << "GHistIndexMatrix will not change with size " << gidx.index.Size() << std::endl;
auto cut_ptrs = gidx.Cuts().Ptrs();
auto cut_values = gidx.Cuts().Values();
// cut points: feature 0 start (0), feature 1 start, feature 2 start, ... feature n start
// cut value: cut for feature 0 slot 0, ..., feature 0 slot m, feature 1 slot 0, ...
std::cout << "size of the cut points and cut values: "
<< cut_ptrs.size() << " " << cut_values.size() << std::endl;
std::cout << "first sample falls to: [feature_id, slot #, cutValue]: " << std::endl;
for (std::size_t i = 0; i < cut_ptrs.size()-1; ++i) {
auto slot_number = gidx.GetGindex(0, i);
std::cout << "[" << i << ", " << slot_number << ", "<< cut_values[slot_number] << "] ";
}
std::cout << std::endl;
std::cout << "------------------------------" << std::endl;
}

if (is_distributed_ && is_col_split_ && is_secure_) {
// Call the interface to transmit the row set collection and gidx to the secure worker
// for encrypted histogram compuation
if ((collective::GetRank() == 0)) {
std::cout << "------------CALL interface to transmit row & gidx---------" << std::endl;
}
processor_instance->InitAggregationContext(gidx);
// get the encrypted histogram from the secure worker
hist_data = processor_instance->ProcessAggregation(nodes_to_build, row_set_collection);
Expand Down Expand Up @@ -247,53 +207,31 @@ class HistogramBuilder {
// note that only Label Owner needs the global histogram
CHECK(!nodes_to_build.empty());


// Front item of nodes_to_build
auto first_nidx = nodes_to_build.front();
// *2 because we have a pair of g and h for each histogram item
std::size_t n = n_total_bins * nodes_to_build.size() * 2;
/*
// Use AllGather to collect the histogram entries from all nodes
// allocate memory for the received entries as a flat vector
std::vector<double> hist_flat;
// iterate through the nodes_to_build
auto it = reinterpret_cast<double *>(hist_data.data());
for (size_t i = 0; i < n; i++) {
// get item with iterator
double item = *it;
hist_flat.push_back(item);
it++;
}
*/

// Perform AllGather
auto hist_vec = std::vector<std::int8_t>(hist_data.data(), hist_data.data() + hist_data.size());

auto hist_entries = collective::Allgather(hist_vec);
// Call interface here to post-process the messages
if (collective::GetRank() == 0) {
std::cout << "---------------CALL Interface for processing-------------- " << std::endl;
}
auto hist_span = common::Span<std::int8_t>(hist_entries.data(), hist_entries.size());
std::vector<double> hist_aggr = processor_instance->HandleAggregation(hist_span);
std::cout << "aggregated size: " << hist_aggr.size() << std::endl;

// Update histogram for label owner
if (collective::GetRank() == 0) {
// iterator of the beginning of the vector
auto it = reinterpret_cast<double *>(this->hist_[first_nidx].data());
// iterate through the hist vector of the label owner
std::cout << "Histogram size n=" << n << std::endl;
for (size_t i = 0; i < n; i++) {
// skip rank 0, as local hist already contains its own entries
// get the sum of the entries from other ranks
// get the sum of the entries from all ranks
double hist_sum = 0.0;
for (std::size_t rank_idx = 0; rank_idx < hist_aggr.size()/n; rank_idx++) {
int flat_idx = rank_idx * n + i;
hist_sum += hist_aggr[flat_idx];
}
// add other parties' sum to rank 0's record
// to get the global histogram
// update rank 0's record with the global histogram
*it = hist_sum;
it++;
}
Expand Down Expand Up @@ -403,14 +341,6 @@ class MultiHistogramBuilder {
std::vector<bst_node_t> nodes_to_sub(valid_candidates.size());
AssignNodes(p_tree, valid_candidates, nodes_to_build, nodes_to_sub);

// print index for nodes_to_build and nodes_to_sub
if (collective::GetRank() == 0) {
for (std::size_t i = 0; i < nodes_to_build.size(); i++) {
std::cout<< "Left-Right: nodes_to_build index " << nodes_to_build[i] << "; ";
std::cout<< "nodes_to_sub index " << nodes_to_sub[i] << std::endl;
}
}

// use the first builder for getting number of valid nodes.
target_builders_.front().AddHistRows(p_tree, &nodes_to_build, &nodes_to_sub, true);
CHECK_GE(nodes_to_build.size(), nodes_to_sub.size());
Expand All @@ -428,10 +358,6 @@ class MultiHistogramBuilder {
for (bst_target_t t = 0; t < p_tree->NumTargets(); ++t) {
auto t_gpair = gpair.Slice(linalg::All(), t);

if (collective::GetRank() == 0) {
std::cout<< "Total row count: " << p_fmat->Info().num_row_ << std::endl;
}

CHECK_EQ(t_gpair.Shape(0), p_fmat->Info().num_row_);
this->target_builders_[t].BuildHist(page_idx, space, page,
partitioners[page_idx].Partitions(), nodes_to_build,
Expand Down

0 comments on commit d881d84

Please sign in to comment.