Add travis sanitizers tests. (#3557)
* Add travis sanitizers tests. * Add gcc-7 in Travis. * Add SANITIZER_PATH for CMake. * Enable sanitizer tests in Travis. * Fix memory leaks in tests. * Fix all memory leaks reported by Address Sanitizer. * tests/cpp/helpers.h/CreateDMatrix now returns raw pointer.
This commit is contained in:
committed by
Rory Mitchell
parent
983cb0b374
commit
cf2d86a4f6
@@ -7,45 +7,48 @@ namespace common {
|
||||
TEST(DenseColumn, Test) {
|
||||
auto dmat = CreateDMatrix(100, 10, 0.0);
|
||||
GHistIndexMatrix gmat;
|
||||
gmat.Init(dmat.get(), 256);
|
||||
gmat.Init((*dmat).get(), 256);
|
||||
ColumnMatrix column_matrix;
|
||||
column_matrix.Init(gmat, 0.2);
|
||||
|
||||
for (auto i = 0ull; i < dmat->Info().num_row_; i++) {
|
||||
for (auto j = 0ull; j < dmat->Info().num_col_; j++) {
|
||||
for (auto i = 0ull; i < (*dmat)->Info().num_row_; i++) {
|
||||
for (auto j = 0ull; j < (*dmat)->Info().num_col_; j++) {
|
||||
auto col = column_matrix.GetColumn(j);
|
||||
EXPECT_EQ(gmat.index[i * dmat->Info().num_col_ + j],
|
||||
EXPECT_EQ(gmat.index[i * (*dmat)->Info().num_col_ + j],
|
||||
col.GetGlobalBinIdx(i));
|
||||
}
|
||||
}
|
||||
delete dmat;
|
||||
}
|
||||
|
||||
TEST(SparseColumn, Test) {
|
||||
auto dmat = CreateDMatrix(100, 1, 0.85);
|
||||
GHistIndexMatrix gmat;
|
||||
gmat.Init(dmat.get(), 256);
|
||||
gmat.Init((*dmat).get(), 256);
|
||||
ColumnMatrix column_matrix;
|
||||
column_matrix.Init(gmat, 0.5);
|
||||
auto col = column_matrix.GetColumn(0);
|
||||
ASSERT_EQ(col.Size(), gmat.index.size());
|
||||
for (auto i = 0ull; i < col.Size(); i++) {
|
||||
EXPECT_EQ(gmat.index[gmat.row_ptr[col.GetRowIdx(i)]],
|
||||
col.GetGlobalBinIdx(i));
|
||||
}
|
||||
auto col = column_matrix.GetColumn(0);
|
||||
ASSERT_EQ(col.Size(), gmat.index.size());
|
||||
for (auto i = 0ull; i < col.Size(); i++) {
|
||||
EXPECT_EQ(gmat.index[gmat.row_ptr[col.GetRowIdx(i)]],
|
||||
col.GetGlobalBinIdx(i));
|
||||
}
|
||||
delete dmat;
|
||||
}
|
||||
|
||||
TEST(DenseColumnWithMissing, Test) {
|
||||
auto dmat = CreateDMatrix(100, 1, 0.5);
|
||||
GHistIndexMatrix gmat;
|
||||
gmat.Init(dmat.get(), 256);
|
||||
gmat.Init((*dmat).get(), 256);
|
||||
ColumnMatrix column_matrix;
|
||||
column_matrix.Init(gmat, 0.2);
|
||||
auto col = column_matrix.GetColumn(0);
|
||||
for (auto i = 0ull; i < col.Size(); i++) {
|
||||
if (col.IsMissing(i)) continue;
|
||||
EXPECT_EQ(gmat.index[gmat.row_ptr[col.GetRowIdx(i)]],
|
||||
col.GetGlobalBinIdx(i));
|
||||
}
|
||||
auto col = column_matrix.GetColumn(0);
|
||||
for (auto i = 0ull; i < col.Size(); i++) {
|
||||
if (col.IsMissing(i)) continue;
|
||||
EXPECT_EQ(gmat.index[gmat.row_ptr[col.GetRowIdx(i)]],
|
||||
col.GetGlobalBinIdx(i));
|
||||
}
|
||||
delete dmat;
|
||||
}
|
||||
} // namespace common
|
||||
} // namespace xgboost
|
||||
|
||||
@@ -22,7 +22,7 @@ TEST(gpu_hist_util, TestDeviceSketch) {
|
||||
DMatrixHandle dmat_handle;
|
||||
XGDMatrixCreateFromMat(test_data.data(), nrows, 1, -1,
|
||||
&dmat_handle);
|
||||
auto dmat = *static_cast<std::shared_ptr<xgboost::DMatrix> *>(dmat_handle);
|
||||
auto dmat = static_cast<std::shared_ptr<xgboost::DMatrix> *>(dmat_handle);
|
||||
|
||||
// parameters for finding quantiles
|
||||
tree::TrainParam p;
|
||||
@@ -34,15 +34,15 @@ TEST(gpu_hist_util, TestDeviceSketch) {
|
||||
|
||||
// find quantiles on the CPU
|
||||
HistCutMatrix hmat_cpu;
|
||||
hmat_cpu.Init(dmat.get(), p.max_bin);
|
||||
hmat_cpu.Init((*dmat).get(), p.max_bin);
|
||||
|
||||
// find the cuts on the GPU
|
||||
dmlc::DataIter<SparsePage>* iter = dmat->RowIterator();
|
||||
dmlc::DataIter<SparsePage>* iter = (*dmat)->RowIterator();
|
||||
iter->BeforeFirst();
|
||||
CHECK(iter->Next());
|
||||
const SparsePage& batch = iter->Value();
|
||||
HistCutMatrix hmat_gpu;
|
||||
DeviceSketch(batch, dmat->Info(), p, &hmat_gpu);
|
||||
DeviceSketch(batch, (*dmat)->Info(), p, &hmat_gpu);
|
||||
CHECK(!iter->Next());
|
||||
|
||||
// compare the cuts
|
||||
@@ -54,6 +54,8 @@ TEST(gpu_hist_util, TestDeviceSketch) {
|
||||
for (int i = 0; i < hmat_gpu.cut.size(); ++i) {
|
||||
ASSERT_LT(fabs(hmat_cpu.cut[i] - hmat_gpu.cut[i]), eps * nrows);
|
||||
}
|
||||
|
||||
delete dmat;
|
||||
}
|
||||
|
||||
} // namespace common
|
||||
|
||||
Reference in New Issue
Block a user