/home/runner/work/HiCR/HiCR/include/hicr/backends/nosv/common.hpp Source File

HiCR: /home/runner/work/HiCR/HiCR/include/hicr/backends/nosv/common.hpp Source File
HiCR
common.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 <cstdio>
27#include <cstdlib>
28#include <pthread.h>
29#include <unistd.h>
30#include <sys/syscall.h> // For syscall(SYS_gettid)
31#include <nosv.h>
32#include <nosv/hwinfo.h>
33
35
41inline void check(int error)
42{
43 if (error == NOSV_SUCCESS) { return; }
44
45 HICR_THROW_RUNTIME("nOS-V Error: %s\n", nosv_get_error_string(error));
46}
47
56inline void *getTaskMetadata(nosv_task_t task)
57{
58 auto metadata = nosv_get_task_metadata(task);
59 if (metadata == NULL) HICR_THROW_RUNTIME("nOS-V metadata task returned NULL:\n");
60 return metadata;
61}
62
71inline void *getTaskTypeMetadata(nosv_task_t task)
72{
73 auto metadata = nosv_get_task_type_metadata(nosv_get_task_type(task));
74 if (metadata == NULL) HICR_THROW_RUNTIME("nOS-V metadata task type returned NULL:\n");
75 return metadata;
76}
77
81inline void print_CPU_TID() { printf("[CPU: %d Thread: %ld] ", nosv_get_current_logical_cpu(), syscall(SYS_gettid)); }
82
88inline void print(const char *message)
89{
91 printf("%s\n", message);
92
93 fflush(stdout);
94}
void print(const char *message)
Definition common.hpp:88
void check(int error)
Definition common.hpp:41
void print_CPU_TID()
Definition common.hpp:81
void * getTaskTypeMetadata(nosv_task_t task)
Definition common.hpp:71
void * getTaskMetadata(nosv_task_t task)
Definition common.hpp:56
Provides a failure model and corresponding exception classes.
#define HICR_THROW_RUNTIME(...)
Definition exceptions.hpp:74