/home/runner/work/HiCR/HiCR/include/hicr/backends/pthreads/executionState.hpp Source File

HiCR: /home/runner/work/HiCR/HiCR/include/hicr/backends/pthreads/executionState.hpp Source File
HiCR
executionState.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2025 Huawei Technologies Co., Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
24#pragma once
25
26#include <functional>
27#include <hicr/core/definitions.hpp>
30
31namespace HiCR::backend::pthreads
32{
33
38{
39 public:
40
46 __INLINE__ ExecutionState(const std::shared_ptr<HiCR::ExecutionUnit> &executionUnit, void *const argument = nullptr)
47 : HiCR::ExecutionState(executionUnit),
48 _argument(argument)
49 {
50 // Getting up-casted pointer for the execution unit
51 auto e = static_pointer_cast<pthreads::ExecutionUnit>(executionUnit);
52
53 // Checking whether the execution unit passed is compatible with this backend
54 if (e == nullptr) HICR_THROW_LOGIC("The passed execution of type '%s' is not supported by this backend\n", executionUnit->getType().c_str());
55
56 // Getting function to execution from the execution unit
57 _fc = e->getFunction();
58 }
59
60 protected:
61
62 __INLINE__ void resumeImpl() override
63 {
64 // Starting the function, passing its argument. It runs to completion.
65 _fc(_argument);
66
67 // Setting as finished
68 _hasFinished = true;
69 }
70
71 __INLINE__ void suspendImpl() override { HICR_THROW_LOGIC("Pthreads execution states do not support the 'suspend' operation"); }
72
73 __INLINE__ bool checkFinalizationImpl() override { return _hasFinished; }
74
75 private:
76
81
85 void *const _argument;
86
90 bool _hasFinished = false;
91};
92
93} // namespace HiCR::backend::pthreads
This file implements the abstract execution unit class for the Pthreads backend.
Definition executionState.hpp:38
Definition executionState.hpp:38
__INLINE__ void resumeImpl() override
Definition executionState.hpp:62
__INLINE__ bool checkFinalizationImpl() override
Definition executionState.hpp:73
__INLINE__ ExecutionState(const std::shared_ptr< HiCR::ExecutionUnit > &executionUnit, void *const argument=nullptr)
Definition executionState.hpp:46
__INLINE__ void suspendImpl() override
Definition executionState.hpp:71
std::function< void(void *)> pthreadFc_t
Definition executionUnit.hpp:44
Provides a base definition for a HiCR Execution State class.
#define HICR_THROW_LOGIC(...)
Definition exceptions.hpp:67