Commit 55890e1a by Ben Clayton

CMake: Add build rules for google benchmark.

Add a single Reactor Coroutine benchmark so there's something to compile. Bug: b/148660286 Change-Id: Icbc4c44dd5c0f1ab495c3b8eddce6ea90199e987 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/40809Tested-by: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarAntonio Maiorano <amaiorano@google.com>
parent f4d09713
...@@ -110,6 +110,7 @@ option_if_not_defined(SWIFTSHADER_USE_GROUP_SOURCES "Group the source files in a ...@@ -110,6 +110,7 @@ option_if_not_defined(SWIFTSHADER_USE_GROUP_SOURCES "Group the source files in a
option_if_not_defined(SWIFTSHADER_BUILD_SAMPLES "Build sample programs" 1) option_if_not_defined(SWIFTSHADER_BUILD_SAMPLES "Build sample programs" 1)
option_if_not_defined(SWIFTSHADER_BUILD_TESTS "Build test programs" 1) option_if_not_defined(SWIFTSHADER_BUILD_TESTS "Build test programs" 1)
option_if_not_defined(SWIFTSHADER_BUILD_BENCHMARKS "Build benchmarks" 0)
option_if_not_defined(SWIFTSHADER_MSAN "Build with memory sanitizer" 0) option_if_not_defined(SWIFTSHADER_MSAN "Build with memory sanitizer" 0)
option_if_not_defined(SWIFTSHADER_ASAN "Build with address sanitizer" 0) option_if_not_defined(SWIFTSHADER_ASAN "Build with address sanitizer" 0)
...@@ -160,17 +161,32 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) ...@@ -160,17 +161,32 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Initialize submodules # Initialize submodules
########################################################### ###########################################################
if (NOT TARGET gtest) if (SWIFTSHADER_BUILD_TESTS)
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/googletest/.git) if (NOT TARGET gtest)
message(WARNING " if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/googletest/.git)
third_party/googletest submodule missing. message(WARNING "
Running 'git submodule update --init' to download it: third_party/googletest submodule missing.
") Running 'git submodule update --init' to download it:
")
execute_process(COMMAND git submodule update --init ${CMAKE_CURRENT_SOURCE_DIR}/third_party/googletest) execute_process(COMMAND git submodule update --init ${CMAKE_CURRENT_SOURCE_DIR}/third_party/googletest)
endif()
endif() endif()
endif() endif()
if(SWIFTSHADER_BUILD_BENCHMARKS)
if (NOT TARGET benchmark::benchmark)
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/benchmark/.git)
message(WARNING "
third_party/benchmark submodule missing.
Running 'git submodule update --init' to download it:
")
execute_process(COMMAND git submodule update --init ${CMAKE_CURRENT_SOURCE_DIR}/third_party/benchmark)
endif()
endif()
endif(SWIFTSHADER_BUILD_BENCHMARKS)
if (NOT TARGET libbacktrace) if (NOT TARGET libbacktrace)
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/libbacktrace/src/.git) if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/libbacktrace/src/.git)
message(WARNING " message(WARNING "
...@@ -2302,6 +2318,25 @@ if(SWIFTSHADER_BUILD_TESTS) ...@@ -2302,6 +2318,25 @@ if(SWIFTSHADER_BUILD_TESTS)
endif() endif()
endif(SWIFTSHADER_BUILD_TESTS) endif(SWIFTSHADER_BUILD_TESTS)
if(SWIFTSHADER_BUILD_BENCHMARKS)
if (NOT TARGET benchmark::benchmark)
set(BENCHMARK_ENABLE_TESTING FALSE CACHE BOOL FALSE FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/benchmark)
endif()
set(REACTOR_BENCHMARK_LIST
${SOURCE_DIR}/Reactor/ReactorBenchmarks.cpp
)
add_executable(ReactorBenchmarks ${REACTOR_BENCHMARK_LIST})
target_link_libraries(ReactorBenchmarks benchmark::benchmark ${Reactor})
set_target_properties(ReactorBenchmarks PROPERTIES
COMPILE_OPTIONS "${SWIFTSHADER_COMPILE_OPTIONS}"
FOLDER "Benchmarks"
)
endif(SWIFTSHADER_BUILD_BENCHMARKS)
if(SWIFTSHADER_BUILD_TESTS AND SWIFTSHADER_BUILD_VULKAN) if(SWIFTSHADER_BUILD_TESTS AND SWIFTSHADER_BUILD_VULKAN)
set(VK_UNITTESTS_LIST set(VK_UNITTESTS_LIST
${CMAKE_CURRENT_SOURCE_DIR}/tests/VulkanUnitTests/Device.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tests/VulkanUnitTests/Device.cpp
......
// Copyright 2020 The SwiftShader Authors. All Rights Reserved.
//
// 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 "Coroutine.hpp"
#include "Reactor.hpp"
#include "benchmark/benchmark.h"
BENCHMARK_MAIN();
class Coroutines : public benchmark::Fixture
{
public:
void SetUp(const ::benchmark::State &state) {}
void TearDown(const ::benchmark::State &state) {}
};
BENCHMARK_F(Coroutines, Fibonacci)
(benchmark::State &state)
{
using namespace rr;
if(!Caps.CoroutinesSupported)
{
state.SkipWithError("Coroutines are not supported");
return;
}
Coroutine<int()> function;
{
Yield(Int(0));
Yield(Int(1));
Int current = 1;
Int next = 1;
While(true)
{
Yield(next);
auto tmp = current + next;
current = next;
next = tmp;
}
}
auto coroutine = function();
int out = 0;
for(auto _ : state)
{
coroutine->await(out);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment