Skip to content

Commit

Permalink
Add optional ComputeCpp version to benchmark attrs
Browse files Browse the repository at this point in the history
Different versions of ComputeCpp can provide performance gains and are
closely tied to the version of compute++ used, in turn providing further
performance improvements. The inclusion of the version is optional to
avoid a hard dependency on ComputeCpp.
  • Loading branch information
danielsoutar committed Apr 25, 2019
1 parent e3a19a5 commit c568192
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 1 deletion.
43 changes: 42 additions & 1 deletion bench/CMakeLists.txt
Expand Up @@ -40,7 +40,48 @@ add_custom_command(OUTPUT git_config.h
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
)
add_library(bench_main STATIC bench_main.cc git_config.h)

# Assume ComputeCpp not available by default.
set(ComputeCpp_INFO_AVAILABLE false)
set(ComputeCpp_VERSION_NUMBER "N/A")
set(ComputeCpp_EDITION "N/A")
set(ComputeCpp_CLANG_BUILD "N/A")
set(ComputeCpp_LLVM_BUILD "N/A")

if(ComputeCpp_FOUND)
execute_process(COMMAND ${ComputeCpp_DEVICE_COMPILER_EXECUTABLE} "--version"
OUTPUT_VARIABLE ComputeCpp_DEVICE_COMPILER_VERSION
RESULT_VARIABLE ComputeCpp_DEVICE_COMPILER_EXECUTABLE_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT ComputeCpp_DEVICE_COMPILER_EXECUTABLE_RESULT EQUAL "0")
message(WARNING "Compute++ not found - Error obtaining device compiler and ComputeCpp version!")
else()
# Store information about ComputeCpp/compiler for benchmarking.
set(ComputeCpp_INFO_AVAILABLE true)
string(REGEX MATCH
"(CE|PE|RC)" ComputeCpp_EDITION ${ComputeCpp_DEVICE_COMPILER_VERSION})
if(${ComputeCpp_EDITION} STREQUAL "RC")
set(ComputeCpp_EDITION "Internal")
endif()
string(REGEX MATCH
"([0-9]+\.[0-9]+\.[0-9]+)" ComputeCpp_VERSION_NUMBER ${ComputeCpp_DEVICE_COMPILER_VERSION})
string(REGEX MATCH
"clang\.git ([0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])"
ComputeCpp_CLANG_BUILD ${ComputeCpp_DEVICE_COMPILER_VERSION})
string(REGEX MATCH
"llvm\.git ([0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])"
ComputeCpp_LLVM_BUILD ${ComputeCpp_DEVICE_COMPILER_VERSION})

set(CLANG_HASH_OFFSET 10)
string(SUBSTRING ${ComputeCpp_CLANG_BUILD} ${CLANG_HASH_OFFSET} -1 ComputeCpp_CLANG_BUILD)
set(LLVM_HASH_OFFSET 9)
string(SUBSTRING ${ComputeCpp_LLVM_BUILD} ${LLVM_HASH_OFFSET} -1 ComputeCpp_LLVM_BUILD)
endif()
endif()

configure_file(computecpp_version_config.h.in computecpp_version_config.h @ONLY)

add_library(bench_main STATIC bench_main.cc git_config.h computecpp_version_config.h)
target_link_libraries(bench_main benchmark::benchmark)
target_include_directories(bench_main PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

Expand Down
1 change: 1 addition & 0 deletions bench/bench_main.cc
@@ -1,4 +1,5 @@
#include <benchmark/benchmark.h>
#include "computecpp_version_config.h"
#include "git_config.h"

BENCHMARK_MAIN();
28 changes: 28 additions & 0 deletions bench/computecpp_version_config.h.in
@@ -0,0 +1,28 @@
/*
* Copyright 2019 Codeplay Software Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use these files 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.
*/

#ifndef COMPUTECPP_VERSION_CONFIG_H_
#define COMPUTECPP_VERSION_CONFIG_H_

extern bool const computecpp_available = @ComputeCpp_INFO_AVAILABLE@;

extern char const* const computecpp_version = "@ComputeCpp_VERSION_NUMBER@";
extern char const* const computecpp_edition = "@ComputeCpp_EDITION@";

extern char const* const clang_git_hash = "@ComputeCpp_CLANG_BUILD@";
extern char const* const llvm_git_hash = "@ComputeCpp_LLVM_BUILD@";

#endif // COMPUTECPP_VERSION_CONFIG_H_
2 changes: 2 additions & 0 deletions bench/conv2d/snn_fixture.h
Expand Up @@ -21,6 +21,7 @@

#include "src/backend/backend_provider.h"

#include "bench/fixture/add_computecpp_info.h"
#include "bench/fixture/add_sycl_device_info.h"
#include "bench/fixture/statistic.h"
#include "bench/fixture/string_reporter.h"
Expand Down Expand Up @@ -54,6 +55,7 @@ class SNNConvolutionBenchmark
auto& backend = this->get_backend();
auto dev = backend.get_queue().get_device();
sycldnn::bench::device_info::add_opencl_device_info(dev, *this);
sycldnn::bench::computecpp_info::add_computecpp_version(*this);

this->add_to_label("@conv_type", sycldnn::bench::TypeName<ConvType>::name);
this->add_to_label("@selector", selector.name());
Expand Down
2 changes: 2 additions & 0 deletions bench/depthwise_conv2d/snn_fixture.h
Expand Up @@ -21,6 +21,7 @@

#include "src/backend/backend_provider.h"

#include "bench/fixture/add_computecpp_info.h"
#include "bench/fixture/add_sycl_device_info.h"
#include "bench/fixture/statistic.h"
#include "bench/fixture/string_reporter.h"
Expand Down Expand Up @@ -52,6 +53,7 @@ class SNNDepthwiseConvolutionBenchmark
auto& backend = this->get_backend();
auto dev = backend.get_queue().get_device();
sycldnn::bench::device_info::add_opencl_device_info(dev, *this);
sycldnn::bench::computecpp_info::add_computecpp_version(*this);

this->add_to_label("@conv_type", sycldnn::bench::TypeName<ConvType>::name);
this->add_to_label("@backend", backend.name());
Expand Down
59 changes: 59 additions & 0 deletions bench/fixture/add_computecpp_info.h
@@ -0,0 +1,59 @@
/*
* Copyright 2019 Codeplay Software Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use these files 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.
*/
#ifndef SYCLDNN_BENCH_FIXTURE_ADD_COMPUTECPP_INFO_H_
#define SYCLDNN_BENCH_FIXTURE_ADD_COMPUTECPP_INFO_H_

#include <CL/sycl.hpp>

#include "string_reporter.h"

extern bool const computecpp_available;

extern char const* const computecpp_version;
extern char const* const computecpp_edition;

extern char const* const clang_git_hash;
extern char const* const llvm_git_hash;

namespace sycldnn {
namespace bench {
namespace computecpp_info {

/**
* Add ComputeCpp meta-data (if available) to the benchmark label. The
* version of compute++ is tied to the version of ComputeCpp, so the associated
* meta-data of compute++ will be the same.
*
* SYCL-DNN benchmarks will include these attributes only if ComputeCpp info is
* available. Benchmarks from other libraries such as MKL-DNN will never include
* them.
*
* \param [out] reporter The benchmark string reporter to add the info to.
*/
inline void add_computecpp_version(StringReporter& reporter) {
if (computecpp_available) {
reporter.add_to_label("@computecpp-version", computecpp_version);
reporter.add_to_label("@computecpp-edition", computecpp_edition);
reporter.add_to_label("@clang", clang_git_hash);
reporter.add_to_label("@llvm", llvm_git_hash);
}
}

} // namespace computecpp_info
} // namespace bench
} // namespace sycldnn

#endif // SYCLDNN_BENCH_FIXTURE_ADD_COMPUTECPP_INFO_H_
2 changes: 2 additions & 0 deletions bench/internal/tiled_conv2d_benchmark.cc
Expand Up @@ -35,6 +35,7 @@
#include "src/backend/backend_provider.h"
#include "src/backend/snn_backend_provider.h"

#include "bench/fixture/add_computecpp_info.h"
#include "bench/fixture/add_sycl_device_info.h"
#include "bench/fixture/base_executor.h"
#include "bench/fixture/statistic.h"
Expand Down Expand Up @@ -175,6 +176,7 @@ void TiledConvolutionBenchmark<

add_to_label("selector", "TiledSelector");
add_to_label("git_hash", commit_hash);
sycldnn::bench::computecpp_info::add_computecpp_version(*this);
set_label(state);
this->finish_benchmark(state);
}
Expand Down
2 changes: 2 additions & 0 deletions bench/pointwise/snn_fixture.h
Expand Up @@ -21,6 +21,7 @@

#include "src/backend/backend_provider.h"

#include "bench/fixture/add_computecpp_info.h"
#include "bench/fixture/add_sycl_device_info.h"
#include "bench/fixture/operator_typenames.h"
#include "bench/fixture/statistic.h"
Expand Down Expand Up @@ -53,6 +54,7 @@ class SNNPointwiseBenchmark
auto& backend = this->get_backend();
auto dev = backend.get_queue().get_device();
sycldnn::bench::device_info::add_opencl_device_info(dev, *this);
sycldnn::bench::computecpp_info::add_computecpp_version(*this);

this->add_to_label("@operator",
sycldnn::bench::OperatorTypeName<Operator>::name);
Expand Down
2 changes: 2 additions & 0 deletions bench/pooling/snn_fixture.h
Expand Up @@ -21,6 +21,7 @@

#include "src/backend/backend_provider.h"

#include "bench/fixture/add_computecpp_info.h"
#include "bench/fixture/add_sycl_device_info.h"
#include "bench/fixture/operator_typenames.h"
#include "bench/fixture/statistic.h"
Expand Down Expand Up @@ -54,6 +55,7 @@ class SNNPoolingBenchmark
auto& backend = this->get_backend();
auto dev = backend.get_queue().get_device();
sycldnn::bench::device_info::add_opencl_device_info(dev, *this);
sycldnn::bench::computecpp_info::add_computecpp_version(*this);

this->add_to_label("@operator",
sycldnn::bench::OperatorTypeName<Operator>::name);
Expand Down

0 comments on commit c568192

Please sign in to comment.