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

HiCR: /home/runner/work/HiCR/HiCR/include/hicr/core/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
23#pragma once
24
25#include <memory>
26#include <hicr/core/definitions.hpp>
29
30namespace HiCR
31{
32
38{
39 public:
40
71
75 __INLINE__ void resume()
76 {
77 if (_state != state_t::initialized && _state != state_t::suspended)
78 HICR_THROW_RUNTIME("Attempting to resume an execution state that is not in a initialized or suspended state (State: %d).\n", _state);
79
80 // Setting state as running
81 _state = state_t::running;
82
83 // Calling internal implementation of the suspend routine
84 resumeImpl();
85 }
86
90 __INLINE__ void suspend()
91 {
92 if (_state != state_t::running) HICR_THROW_RUNTIME("Attempting to suspend an execution state that is not in a running state (State: %d).\n", _state);
93
94 // Setting state as suspended
95 _state = state_t::suspended;
96
97 // Calling internal implementation of the suspend routine
99 }
100
106 __INLINE__ bool checkFinalization()
107 {
108 // Calling internal implementation of the checkFinalization routine
109 auto isFinished = checkFinalizationImpl();
110
111 // Updating internal state
112 if (isFinished == true) _state = state_t::finished;
113
114 // Returning value
115 return isFinished;
116 }
117
123 __INLINE__ state_t getState() { return _state; }
124
128 ExecutionState() = delete;
129
133 virtual ~ExecutionState() = default;
134
135 protected:
136
142 ExecutionState(const std::shared_ptr<HiCR::ExecutionUnit> &executionUnit){};
143
147 virtual void resumeImpl() = 0;
148
152 virtual void suspendImpl() = 0;
153
159 virtual bool checkFinalizationImpl() = 0;
160
161 private:
162
167};
168
169} // namespace HiCR
Definition executionState.hpp:38
virtual void suspendImpl()=0
state_t
Definition executionState.hpp:45
@ initialized
Definition executionState.hpp:54
@ finished
Definition executionState.hpp:69
@ uninitialized
Definition executionState.hpp:49
@ suspended
Definition executionState.hpp:64
@ running
Definition executionState.hpp:59
__INLINE__ void suspend()
Definition executionState.hpp:90
__INLINE__ bool checkFinalization()
Definition executionState.hpp:106
virtual void resumeImpl()=0
ExecutionState(const std::shared_ptr< HiCR::ExecutionUnit > &executionUnit)
Definition executionState.hpp:142
__INLINE__ state_t getState()
Definition executionState.hpp:123
virtual ~ExecutionState()=default
virtual bool checkFinalizationImpl()=0
__INLINE__ void resume()
Definition executionState.hpp:75
Provides a base definition for a HiCR Execution Unit class.
Provides a failure model and corresponding exception classes.
#define HICR_THROW_RUNTIME(...)
Definition exceptions.hpp:74