From faf2ba7c5fa4ea812772313db052bdf772117f4b Mon Sep 17 00:00:00 2001 From: "Ryan M. Richard" Date: Thu, 24 Apr 2025 22:36:38 -0500 Subject: [PATCH 1/2] adds profile tests --- CMakeLists.txt | 11 ++++++++ .../tensorwrapper/contraction.cpp | 21 +++++++++++++++ .../tensorwrapper/performance_testing.hpp | 22 +++++++++++++++ .../tensorwrapper/test_main.cpp | 27 +++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 tests/cxx/performance_tests/tensorwrapper/contraction.cpp create mode 100644 tests/cxx/performance_tests/tensorwrapper/performance_testing.hpp create mode 100644 tests/cxx/performance_tests/tensorwrapper/test_main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3036316d..b39e8db6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,10 @@ if("${BUILD_TESTING}") cxx_acceptance_test_dir "${cxx_test_dir}/acceptance_tests/${PROJECT_NAME}" ) + set( + cxx_performance_test_dir + "${cxx_test_dir}/performance_tests/${PROJECT_NAME}" + ) set(python_test_dir "${CMAKE_CURRENT_LIST_DIR}/tests/python") set(python_unit_test_dir "${python_test_dir}/unit_tests") @@ -100,6 +104,13 @@ if("${BUILD_TESTING}") DEPENDS Catch2 ${PROJECT_NAME} ) + cmaize_add_tests( + test_performance_${PROJECT_NAME} + SOURCE_DIR "${cxx_performance_test_dir}" + INCLUDE_DIRS "${project_src_dir}" + DEPENDS Catch2 ${PROJECT_NAME} + ) + cmaize_add_tests( acceptance_test_${PROJECT_NAME} SOURCE_DIR "${cxx_acceptance_test_dir}" diff --git a/tests/cxx/performance_tests/tensorwrapper/contraction.cpp b/tests/cxx/performance_tests/tensorwrapper/contraction.cpp new file mode 100644 index 00000000..1fbfb090 --- /dev/null +++ b/tests/cxx/performance_tests/tensorwrapper/contraction.cpp @@ -0,0 +1,21 @@ +#include "performance_testing.hpp" +#include +#include + +using namespace tensorwrapper; + +TEST_CASE("Contraction") { + Tensor A{1.0, 2.0, 3.0}; + Tensor B{4.0, 5.0, 6.0}; + Tensor C; + + auto l = [&A, &B, &C]() { + C("") = A("i") * B("i"); + return C; + }; + + parallelzone::hardware::CPU cpu; + auto [rv, info] = cpu.profile_it(std::move(l)); + + std::cout << "Time in ns: " << info.wall_time.count() << std::endl; +} \ No newline at end of file diff --git a/tests/cxx/performance_tests/tensorwrapper/performance_testing.hpp b/tests/cxx/performance_tests/tensorwrapper/performance_testing.hpp new file mode 100644 index 00000000..456683b3 --- /dev/null +++ b/tests/cxx/performance_tests/tensorwrapper/performance_testing.hpp @@ -0,0 +1,22 @@ +/* + * Copyright 2025 NWChemEx-Project + * + * 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 governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include +#include +#include +#include \ No newline at end of file diff --git a/tests/cxx/performance_tests/tensorwrapper/test_main.cpp b/tests/cxx/performance_tests/tensorwrapper/test_main.cpp new file mode 100644 index 00000000..030cf950 --- /dev/null +++ b/tests/cxx/performance_tests/tensorwrapper/test_main.cpp @@ -0,0 +1,27 @@ +/* + * Copyright 2024 NWChemEx Community + * + * 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 governing permissions and + * limitations under the License. + */ + +#define CATCH_CONFIG_RUNNER +#include +#include + +int main(int argc, char* argv[]) { + auto rt = parallelzone::runtime::RuntimeView(argc, argv); + + int res = Catch::Session().run(argc, argv); + + return res; +} From fa870ce39b1573e6c5a343ac69d2bcd79b6205c5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 25 Apr 2025 03:38:41 +0000 Subject: [PATCH 2/2] Committing clang-format changes --- .../tensorwrapper/contraction.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/cxx/performance_tests/tensorwrapper/contraction.cpp b/tests/cxx/performance_tests/tensorwrapper/contraction.cpp index 1fbfb090..4124b6f4 100644 --- a/tests/cxx/performance_tests/tensorwrapper/contraction.cpp +++ b/tests/cxx/performance_tests/tensorwrapper/contraction.cpp @@ -1,3 +1,19 @@ +/* + * Copyright 2025 NWChemEx-Project + * + * 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 governing permissions and + * limitations under the License. + */ + #include "performance_testing.hpp" #include #include