Skip to content

[pull] master from parallel101:master #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions 08/include/CudaAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ struct CudaAllocator {
::new((void *)p) T(std::forward<Args>(args)...);
}

template <class U> // cihou shabi wendous
constexpr CudaAllocator(CudaAllocator<U> const &other) noexcept {
}

constexpr bool operator==(CudaAllocator<T> const &other) const {
return this == &other;
}
Expand Down
4 changes: 4 additions & 0 deletions 09/include/CudaAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ struct CudaAllocator {
::new((void *)p) T(std::forward<Args>(args)...);
}

template <class U> // cihou shabi wendous
constexpr CudaAllocator(CudaAllocator<U> const &other) noexcept {
}

constexpr bool operator==(CudaAllocator<T> const &other) const {
return this == &other;
}
Expand Down
3 changes: 0 additions & 3 deletions benchtest/.tasks

This file was deleted.

13 changes: 0 additions & 13 deletions benchtest/CMakeLists.txt

This file was deleted.

2 changes: 2 additions & 0 deletions specifelse/benchtest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jomtSettings/
.cache/
4 changes: 4 additions & 0 deletions specifelse/benchtest/.tasks
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[+]
build_type=Release
build_target=demo0
run_target="$(VIM:build_dir)/$(VIM:build_target)" --benchmark_out="$(VIM:build_dir)/$(VIM:build_target).json"
18 changes: 18 additions & 0 deletions specifelse/benchtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.15)

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_STANDARD 17)

project(BenchCourse LANGUAGES CXX)
add_subdirectory(benchmark)

set(DEMO_LIST
demo0
)

foreach (name IN ITEMS ${DEMO_LIST})
add_executable(${name} ${name}.cpp)
target_link_libraries(${name} PRIVATE benchmark)
endforeach()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
68 changes: 68 additions & 0 deletions specifelse/benchtest/demo0.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <benchmark/benchmark.h>
#include <random>
#include <vector>
#include <algorithm>

void upperIfelse(char *p, int n) {
for (int i = 0; i < n; i++) {
if ('a' <= p[i] && p[i] <= 'z')
p[i] = p[i] + 'A' - 'a';
}
}

void upperTernary(char *p, int n) {
for (int i = 0; i < n; i++) {
p[i] = ('a' <= p[i] && p[i] <= 'z') ? p[i] + 'A' - 'a' : p[i];
}
}

template <void (*upper)(char *p, int n)>
void testSorted(benchmark::State &state) {
const int n = (int)1e7;
std::vector<char> a(n);

std::mt19937 rng;
std::uniform_int_distribution<char> dist(0, 127);
for (int i = 0; i < n; i++) {
a[i] = dist(rng);
}
std::sort(a.begin(), a.end());

for (auto _: state) {
upper(a.data(), n);
benchmark::DoNotOptimize(a);
}
}

template <void (*upper)(char *p, int n)>
void testRandom(benchmark::State &state) {
const int n = (int)1e7;
std::vector<char> a(n);

std::mt19937 rng;
std::uniform_int_distribution<char> dist(0, 127);
for (int i = 0; i < n; i++) {
a[i] = dist(rng);
}

for (auto _: state) {
upper(a.data(), n);
benchmark::DoNotOptimize(a);
}
}

BENCHMARK_TEMPLATE(testSorted, upperTernary);
BENCHMARK_TEMPLATE(testSorted, upperIfelse);
BENCHMARK_TEMPLATE(testRandom, upperTernary);
BENCHMARK_TEMPLATE(testRandom, upperIfelse);

BENCHMARK_MAIN();
/*
-------------------------------------------------------------------
Benchmark Time CPU Iterations
-------------------------------------------------------------------
testSorted<upperTernary> 547329 ns 546965 ns 1279
testSorted<upperIfelse> 4597908 ns 4597300 ns 153
testRandom<upperTernary> 548555 ns 548232 ns 1296
testRandom<upperIfelse> 7031812 ns 7031073 ns 87
*/
35 changes: 35 additions & 0 deletions specifelse/benchtest/jomt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# Misc
CMakeLists.txt.user
4 changes: 4 additions & 0 deletions specifelse/benchtest/jomt/.tasks
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[+]
build_type=Release
build_target=JOMT
run_target="$(VIM:build_dir)/src/$(VIM:build_target)"
23 changes: 23 additions & 0 deletions specifelse/benchtest/jomt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.5)

project(JOMT LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (MSVC)
add_compile_options(/W3)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /DNDEBUG /DQT_NO_DEBUG_OUTPUT")
else()
add_compile_options(-Wall -Wextra -pedantic)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -DNDEBUG -DQT_NO_DEBUG_OUTPUT -march=native -mtune=native")
endif()

# Build the target
add_subdirectory(src)
Loading