Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jnke2016 committed Dec 13, 2023
1 parent 6afb913 commit b68381f
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,10 @@ if(BUILD_CUGRAPH_MG_TESTS)
# - MG TRIANGLE COUNT tests -------------------------------------------------------------------
ConfigureTestMG(MG_TRIANGLE_COUNT_TEST community/mg_triangle_count_test.cpp)

###############################################################################################
# - Ktruss tests --------------------------------------------------------------------------
ConfigureTest(KTRUSS_TEST community/ktruss_test.cpp)

###############################################################################################
# - MG INDUCED SUBGRAPH tests -----------------------------------------------------------------
ConfigureTestMG(MG_INDUCED_SUBGRAPH_TEST structure/mg_induced_subgraph_test.cu)
Expand Down
129 changes: 129 additions & 0 deletions cpp/tests/community/ktruss_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION.
*
* Licensed 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 governin_from_mtxg permissions and
* limitations under the License.
*/

#include <utilities/base_fixture.hpp>
#include <utilities/test_graphs.hpp>
#include <utilities/test_utilities.hpp>
#include <utilities/thrust_wrapper.hpp>

#include <cugraph/algorithms.hpp>
#include <cugraph/graph.hpp>
#include <cugraph/graph_functions.hpp>
#include <cugraph/graph_view.hpp>
#include <cugraph/utilities/high_res_timer.hpp>

#include <raft/core/handle.hpp>
#include <raft/util/cudart_utils.hpp>
#include <rmm/device_uvector.hpp>
#include <rmm/mr/device/cuda_memory_resource.hpp>

#include <gtest/gtest.h>

#include <algorithm>
#include <iterator>
#include <limits>
#include <numeric>
#include <random>
#include <vector>


struct Ktruss_Usecase {
int32_t k{10};
bool check_correctness{true};
};

template <typename input_usecase_t>
class Tests_Ktruss
: public ::testing::TestWithParam<std::tuple<Ktruss_Usecase, input_usecase_t>> {
public:
Tests_Ktruss() {}

static void SetUpTestCase() {}
static void TearDownTestCase() {}

virtual void SetUp() {}
virtual void TearDown() {}

template <typename vertex_t, typename edge_t>
void run_current_test(
std::tuple<Ktruss_Usecase const&, input_usecase_t const&> const& param)
{
constexpr bool renumber = false;

using weight_t = float;

auto [ktruss_usecase, input_usecase] = param;

raft::handle_t handle{};
HighResTimer hr_timer{};

if (cugraph::test::g_perf) {
RAFT_CUDA_TRY(cudaDeviceSynchronize()); // for consistent performance measurement
hr_timer.start("MG Construct graph");
}

cugraph::graph_t<vertex_t, edge_t, false, false> graph(handle);
std::optional<rmm::device_uvector<vertex_t>> d_renumber_map_labels{std::nullopt};
std::tie(graph, std::ignore, d_renumber_map_labels) =
cugraph::test::construct_graph<vertex_t, edge_t, weight_t, false, false>(
handle, input_usecase, false, renumber, false, true);

if (cugraph::test::g_perf) {
RAFT_CUDA_TRY(cudaDeviceSynchronize()); // for consistent performance measurement
hr_timer.stop();
hr_timer.display_and_clear(std::cout);
}

auto graph_view = graph.view();

if (cugraph::test::g_perf) {
RAFT_CUDA_TRY(cudaDeviceSynchronize()); // for consistent performance measurement
hr_timer.start("Ktruss");
}

cugraph::ktruss<vertex_t, edge_t, false>(
handle,
graph_view,
ktruss_usecase.k,
false);

if (cugraph::test::g_perf) {
RAFT_CUDA_TRY(cudaDeviceSynchronize()); // for consistent performance measurement
hr_timer.stop();
hr_timer.display_and_clear(std::cout);
}

}
};

using Tests_Ktruss_File = Tests_Ktruss<cugraph::test::File_Usecase>;

// FIXME: add tests for type combinations
TEST_P(Tests_Ktruss_File, CheckInt32Int32)
{
run_current_test<int32_t, int32_t>(override_File_Usecase_with_cmd_line_arguments(GetParam()));
}


INSTANTIATE_TEST_SUITE_P(
file_test,
Tests_Ktruss_File,
::testing::Combine(
// enable correctness checks
::testing::Values(Ktruss_Usecase{2}),
::testing::Values(cugraph::test::File_Usecase("/home/nfs/jnke/debug_jaccard/cugraph/datasets/dummy.mtx"))));

CUGRAPH_TEST_PROGRAM_MAIN()

0 comments on commit b68381f

Please sign in to comment.