Skip to content
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

Add CI workflow for testing documentation examples #1629

Merged
merged 25 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3d6330a
Save progress
kboyarinov Dec 25, 2024
8907e3a
Merge remote-tracking branch 'origin/master' into dev/kboyarinov/test…
kboyarinov Feb 4, 2025
a668456
Commit missed files
kboyarinov Feb 4, 2025
d2f7ea5
Add CI workflow
kboyarinov Feb 5, 2025
0ce3b4b
Fix CI workflow
kboyarinov Feb 5, 2025
99d1bbe
Fix build library stage
kboyarinov Feb 5, 2025
6d16822
Add tmp workflow debug
kboyarinov Feb 5, 2025
9ad06ec
Fix directory
kboyarinov Feb 5, 2025
78a49b1
Add source vars
kboyarinov Feb 5, 2025
2881955
Add end of files
kboyarinov Feb 5, 2025
601df07
Remove .h files use comment tags instead
kboyarinov Feb 5, 2025
9823c70
Add blocked_nd_range example
kboyarinov Feb 5, 2025
1b12acd
Update copyright for ci.yml
kboyarinov Feb 5, 2025
39af2e8
Bump STL version for testing
kboyarinov Feb 5, 2025
b9f1e5e
Add to main CMake lists + Windows workflow
kboyarinov Feb 6, 2025
0c4225b
Add brackets
kboyarinov Feb 6, 2025
00292b9
Separate Windows workflow, remove public CMake option
kboyarinov Feb 6, 2025
e183300
Fix Windows workflow variable name
kboyarinov Feb 6, 2025
53a4bf7
Apply review comments
kboyarinov Feb 6, 2025
9c00370
Add tbbmalloc_proxy
kboyarinov Feb 6, 2025
54ba82d
Add config into the build command on Windows
kboyarinov Feb 6, 2025
78d1b99
Fix arguments order
kboyarinov Feb 6, 2025
dfbb5bf
Update fixed_pool_example.cpp
kboyarinov Feb 11, 2025
72435a3
Fix inclusions for examples
kboyarinov Feb 11, 2025
1840c13
Merge branch 'dev/kboyarinov/testing-doc-examples' of https://github.…
kboyarinov Feb 11, 2025
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
Prev Previous commit
Next Next commit
Remove .h files use comment tags instead
  • Loading branch information
kboyarinov committed Feb 5, 2025
commit 601df070cca41fb2912e6ed415b1c26ade61baed
4 changes: 3 additions & 1 deletion doc/main/reference/custom_mutex_chmap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,7 @@ and ``oneapi::tbb::rw_mutex`` meet the requirements above.
The example below demonstrates how to wrap ``std::shared_mutex`` (C++17) to meet the requirements
of `ReaderWriterMutex` and how to customize ``concurrent_hash_map`` to use this mutex.

.. literalinclude:: ./examples/custom_mutex_chmap_example.h
.. literalinclude:: ./examples/custom_mutex_chmap_example.cpp
:language: c++
:start-after: /*begin_custom_mutex_chmap_example*/
:end-before: /*end_custom_mutex_chmap_example*/
126 changes: 124 additions & 2 deletions doc/main/reference/examples/custom_mutex_chmap_example.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,129 @@
/*
Copyright (c) 2025 Intel 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 governing permissions and
limitations under the License.
*/

#if __cplusplus >= 201703L
#include "custom_mutex_chmap_example.h"

#else
/*begin_custom_mutex_chmap_example*/
#define TBB_PREVIEW_CONCURRENT_HASH_MAP_EXTENSIONS 1
#include "oneapi/tbb/concurrent_hash_map.h"
#include <shared_mutex>

class SharedMutexWrapper {
public:
// ReaderWriterMutex requirements

static constexpr bool is_rw_mutex = true;
static constexpr bool is_recursive_mutex = false;
static constexpr bool is_fair_mutex = false;

class scoped_lock {
public:
scoped_lock() : my_mutex_ptr(nullptr), my_writer_flag(false) {}
scoped_lock(SharedMutexWrapper& mutex, bool write = true)
: my_mutex_ptr(&mutex), my_writer_flag(write)
{
if (my_writer_flag) {
my_mutex_ptr->my_mutex.lock();
} else {
my_mutex_ptr->my_mutex.lock_shared();
}
}

~scoped_lock() {
if (my_mutex_ptr) release();
}

void acquire(SharedMutexWrapper& mutex, bool write = true) {
if (my_mutex_ptr) release();

my_mutex_ptr = &mutex;
my_writer_flag = write;

if (my_writer_flag) {
my_mutex_ptr->my_mutex.lock();
} else {
my_mutex_ptr->my_mutex.lock_shared();
}
}

bool try_acquire(SharedMutexWrapper& mutex, bool write = true) {
if (my_mutex_ptr) release();

my_mutex_ptr = &mutex;

bool result = false;

if (my_writer_flag) {
result = my_mutex_ptr->my_mutex.try_lock();
} else {
result = my_mutex_ptr->my_mutex.try_lock_shared();
}

if (result) my_writer_flag = write;
return result;
}

void release() {
if (my_writer_flag) {
my_mutex_ptr->my_mutex.unlock();
} else {
my_mutex_ptr->my_mutex.unlock_shared();
}
}

bool upgrade_to_writer() {
// std::shared_mutex does not have the upgrade/downgrade semantics
if (my_writer_flag) return true; // Already a writer

my_mutex_ptr->my_mutex.unlock_shared();
my_mutex_ptr->my_mutex.lock();
return false; // The lock was reacquired
}

bool downgrade_to_reader() {
if (!my_writer_flag) return true; // Already a reader

my_mutex_ptr->my_mutex.unlock();
my_mutex_ptr->my_mutex.lock_shared();
return false;
}

bool is_writer() const {
return my_writer_flag;
}

private:
SharedMutexWrapper* my_mutex_ptr;
bool my_writer_flag;
};
private:
std::shared_mutex my_mutex;
}; // struct SharedMutexWrapper

int main() {
using map_type = oneapi::tbb::concurrent_hash_map<int, int,
oneapi::tbb::tbb_hash_compare<int>,
oneapi::tbb::tbb_allocator<std::pair<const int, int>>,
SharedMutexWrapper>;

map_type map; // This object will use SharedMutexWrapper for thread safety of insert/find/erase operations
}
/*end_custom_mutex_chmap_example*/

#else // C++17
// Skip
int main() {}
#endif
104 changes: 0 additions & 104 deletions doc/main/reference/examples/custom_mutex_chmap_example.h

This file was deleted.

18 changes: 18 additions & 0 deletions doc/main/reference/examples/fixed_pool_example.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
Copyright (c) 2025 Intel 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 governing permissions and
limitations under the License.
*/

/*begin_fixed_pool_example*/
#define TBB_PREVIEW_MEMORY_POOL 1
#include "oneapi/tbb/memory_pool.h"

Expand All @@ -8,3 +25,4 @@ int main() {
void* my_ptr = my_pool.malloc(10);
my_pool.free(my_ptr);
}
/*end_fixed_pool_example*/
Original file line number Diff line number Diff line change
@@ -1,6 +1,53 @@
/*
Copyright (c) 2025 Intel 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 governing permissions and
limitations under the License.
*/

#if __cplusplus >= 201703L
#include "helpers_for_expressing_graphs_preview_api_example.h"

/*begin_helpers_for_expressing_graphs_preview_api_example*/
#define TBB_PREVIEW_FLOW_GRAPH_FEATURES 1
#include <oneapi/tbb/flow_graph.h>

int main() {
using namespace oneapi::tbb::flow;

graph g;

function_node doubler(g, unlimited, [](const int& v) { return 2 * v; });
function_node squarer(g, unlimited, [](const int& v) { return v * v; });
function_node cuber(g, unlimited, [](const int& v) { return v * v * v; });

auto handlers = make_node_set(doubler, squarer, cuber);

broadcast_node input(precedes(handlers));
join_node join(follows(handlers));

int sum = 0;
function_node summer(follows(join), serial,
[&](const std::tuple<int, int, int>& v) {
int sub_sum = std::get<0>(v) + std::get<1>(v) + std::get<2>(v);
sum += sub_sum;
return sub_sum;
});

for (int i = 1; i <= 10; ++i) {
input.try_put(i);
}
g.wait_for_all();
}
/*end_helpers_for_expressing_graphs_preview_api_example*/
#else
// Skip
int main() {}
Expand Down

This file was deleted.

Loading
Loading