uvgVPCCenc 1.2.0
uvgVPCCenc is an open-source real-time V-PCC encoder library written in C++ from scratch.
Loading...
Searching...
No Matches
jobManagement.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 * This file is part of uvgVPCCenc V-PCC encoder.
3 *
4 * Copyright (c) 2024-present, Tampere University, ITU/ISO/IEC, project contributors
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright notice, this
14 * list of conditions and the following disclaimer in the documentation and/or
15 * other materials provided with the distribution.
16 *
17 * * Neither the name of Tampere University, ITU/ISO/IEC nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
29 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
32 ****************************************************************************/
33
34#pragma once
35#include <functional>
36#include <memory>
37#include <optional>
38
39#include "threadqueue.hpp"
40#include <robin_hood.h>
41#include "uvgutils/log.hpp"
42
43#define JOBF(gofId, frameId, priority, func, ...) \
44 uvgutils::JobManager::make_job(gofId, frameId, priority, std::string(#func), func, ##__VA_ARGS__)
45
46#define JOBG(gofId, priority, func, ...) uvgutils::JobManager::make_job(gofId, priority, std::string(#func), func, ##__VA_ARGS__)
47
48#define TO_STRING(x) #x
49
50namespace uvgutils {
51
52class jobKey {
53 private:
54 size_t gofId_;
55 std::optional<size_t> frameId_;
56 std::string funcName_;
57
58 public:
59 jobKey(const size_t& gofId, const size_t& frameId, const std::string& funcName);
60 jobKey(const size_t& gofId, const std::string& funcName);
61 std::string toString() const;
62
63 // Getters
64 size_t getGofId() const;
65 std::optional<size_t> getFrameId() const;
66 std::string getFuncName() const;
67
68 bool operator==(const jobKey& other) const;
69};
70} // namespace uvgutils
71
72namespace std {
73template <>
74struct hash<uvgutils::jobKey> {
75 size_t operator()(const uvgutils::jobKey& key) const;
76};
77} // namespace std
78
79namespace uvgutils {
80
81struct JobManager {
82 static std::unique_ptr<ThreadQueue> threadQueue;
83 static std::unique_ptr<robin_hood::unordered_map<jobKey, std::shared_ptr<Job>>> previousGOFJobMap;
84 static std::unique_ptr<robin_hood::unordered_map<jobKey, std::shared_ptr<Job>>> previousFrameJobMap;
85 static std::unique_ptr<robin_hood::unordered_map<jobKey, std::shared_ptr<Job>>> currentGOFJobMap;
86 static std::unique_ptr<robin_hood::unordered_map<jobKey, std::shared_ptr<Job>>> currentFrameJobMap;
87
88 template <typename Func, typename... Args>
89 static std::shared_ptr<Job> make_job(const size_t& gofId, const size_t& frameId, std::size_t priority, std::string funcName, Func&& func,
90 Args&&... args);
91
92 template <typename Func, typename... Args>
93 static std::shared_ptr<Job> make_job(const size_t& gofId, std::size_t priority, std::string funcName, Func&& func, Args&&... args);
94
95 static std::shared_ptr<Job> getJob(size_t gofId, size_t frameId, const std::string& funcName);
96 static std::shared_ptr<Job> getJob(size_t gofId, const std::string& funcName);
97
98 static void initThreadQueue(uint16_t numThreads);
99
100 static void submitCurrentFrameJobs();
101
102 static void submitCurrentGOFJobs();
103};
104} // namespace uvgutils
105
106// Include template implementations
107#include "jobManagement.tpp"
Definition jobManagement.hpp:52
std::optional< size_t > getFrameId() const
Definition jobManagement.cpp:119
size_t getGofId() const
Definition jobManagement.cpp:117
std::string getFuncName() const
Definition jobManagement.cpp:121
bool operator==(const jobKey &other) const
Definition jobManagement.cpp:123
std::string toString() const
Definition jobManagement.cpp:110
Definition jobManagement.hpp:72
Definition jobManagement.hpp:50
Definition jobManagement.hpp:81
static std::shared_ptr< Job > make_job(const size_t &gofId, const size_t &frameId, std::size_t priority, std::string funcName, Func &&func, Args &&... args)
static std::shared_ptr< Job > getJob(size_t gofId, size_t frameId, const std::string &funcName)
Definition jobManagement.cpp:128
static void submitCurrentFrameJobs()
Definition jobManagement.cpp:146
static std::shared_ptr< Job > make_job(const size_t &gofId, std::size_t priority, std::string funcName, Func &&func, Args &&... args)
static std::unique_ptr< robin_hood::unordered_map< jobKey, std::shared_ptr< Job > > > previousGOFJobMap
Definition jobManagement.hpp:83
static void initThreadQueue(uint16_t numThreads)
Definition jobManagement.cpp:139
static void submitCurrentGOFJobs()
Definition jobManagement.cpp:156
static std::unique_ptr< ThreadQueue > threadQueue
Definition jobManagement.hpp:82
static std::unique_ptr< robin_hood::unordered_map< jobKey, std::shared_ptr< Job > > > currentFrameJobMap
Definition jobManagement.hpp:86
static std::unique_ptr< robin_hood::unordered_map< jobKey, std::shared_ptr< Job > > > currentGOFJobMap
Definition jobManagement.hpp:85
static std::unique_ptr< robin_hood::unordered_map< jobKey, std::shared_ptr< Job > > > previousFrameJobMap
Definition jobManagement.hpp:84
size_t gofId
Definition uvgvpccenc.cpp:94