VulkanRaytracingCycles 0.0.0
Cycles Render Engine With VulkanRaytracingShaderModules. ( Experiment , in progress)
front::DeallocatorVk Struct Reference

#include <AllocatorVk.h>

Public Types

typedef bool futType
 typedef std::function<bool(bool)> desType; More...
 
typedef uint32_t queueType
 
typedef Lbd< bool(bool)> desType
 

Public Member Functions

void Dispatch ()
 
bool NipInTheBud ()
 
uint32_t AllocFuture ()
 
bool AllocKiller (ssize_t idx, ssize_t reserve)
 
void ClearBuds ()
 
void Holocaust ()
 
template<class F >
ssize_t ToDoList (F const &f, ssize_t reserve=100)
 
bool Alive (ssize_t ID)
 
bool Kill (ssize_t ID)
 
bool KillForce (ssize_t idx)
 
 ~DeallocatorVk ()
 

Public Attributes

std::unordered_map< std::string, HANDLE > beginThreads
 
std::vector< std::future< futType > > desfuture
 
std::mutex mtx_desfuture
 
std::atomic_bool nib_end
 
bonqueue< uint32_t, 1000000 > buds
 
std::atomic_uint budsNums = { 0 }
 
uint32_t _total = 0
 
desType _ [LBSTA]
 std::vector<desType > _; More...
 
ssize_t idx = 0
 
ssize_t size = 0
 

Detailed Description

Definition at line 1724 of file AllocatorVk.h.

Member Typedef Documentation

◆ desType

typedef Lbd<bool(bool)> front::DeallocatorVk::desType

Definition at line 1731 of file AllocatorVk.h.

◆ futType

typedef std::function<bool(bool)> desType;

Definition at line 1729 of file AllocatorVk.h.

◆ queueType

Definition at line 1730 of file AllocatorVk.h.

Constructor & Destructor Documentation

◆ ~DeallocatorVk()

front::DeallocatorVk::~DeallocatorVk ( )

Holocaust();

Definition at line 2024 of file AllocatorVk.cpp.

2024 {
2026 };

Member Function Documentation

◆ Alive()

bool front::DeallocatorVk::Alive ( ssize_t  ID)
inline

if (InterlockedAdd64((LONG64*)&killer.size, 0) > idx) {

Definition at line 1805 of file AllocatorVk.h.

1805 {
1806
1807 ssize_t idx = ID % killer.size;
1809 if (killer._[idx] == ID) {
1810 return killer._[idx](false);
1811 };
1812 return false;
1813 };

◆ AllocFuture()

uint32_t front::DeallocatorVk::AllocFuture ( )

Definition at line 1898 of file AllocatorVk.cpp.

1898 {
1899 const std::lock_guard<std::mutex> lock(mtx_desfuture);
1900 desfuture.emplace_back();
1901 budsNums.store(budsNums + 1);
1902 return (uint32_t)desfuture.size() - 1;
1903 };
std::vector< std::future< futType > > desfuture
Definition: AllocatorVk.h:1752
std::mutex mtx_desfuture
Definition: AllocatorVk.h:1753
std::atomic_uint budsNums
Definition: AllocatorVk.h:1757

◆ AllocKiller()

bool front::DeallocatorVk::AllocKiller ( ssize_t  idx,
ssize_t  reserve 
)

killer._.resize(size_t(killer.size));

Definition at line 1905 of file AllocatorVk.cpp.

1905 {
1906
1907#if LBSTA == 0
1908 log_allo(" AllocKiller IDX %zd AllocKiller %zu \n", idx, reserve);
1909 EnterCriticalSection(&killer.sectAlloc);
1910
1911 if (idx < killer.size) {
1912 LeaveCriticalSection(&killer.sectAlloc); return true;
1913 };
1914
1915 killer.size += reserve;
1917 desType* tmp = new ((void*)killer._, killer.size * sizeof(desType));
1918 if (tmp != nullptr) {
1919 killer._ = tmp;
1920 tmp = nullptr;
1921 }
1922 else {
1923 LeaveCriticalSection(&sectAlloc);
1924 log_bad("Killer failed to allocate. \n");
1925 return false;
1926 }
1927
1928 log_allo(" IDX %zd AllocKiller %zu \n", idx, killer.size);
1929
1930 LeaveCriticalSection(&sectAlloc);
1931#endif
1932 return true;
1933 };
#define log_allo(...)
Definition: AllocatorVk.h:12
#define log_bad(...)
Definition: log.hpp:37
Lbd< bool(bool)> desType
Definition: AllocatorVk.h:1731

◆ ClearBuds()

void front::DeallocatorVk::ClearBuds ( )

Definition at line 1936 of file AllocatorVk.cpp.

1936 {
1937
1938
1939 uint32_t expected = (uint32_t)desfuture.size()-1;
1940
1941
1942
1943 printf("finalizing ");
1944 while (expected != _InterlockedCompareExchange(&buds.produce, expected, expected)) {
1945 std::this_thread::sleep_for(std::chrono::milliseconds(10));
1946 printf(".");
1947 };
1948
1949 while (expected != _InterlockedCompareExchange(&buds.consume, expected, expected)) {
1950 std::this_thread::sleep_for(std::chrono::milliseconds(10));
1951 printf(".");
1952 };
1953
1954 printf(" ok\n");
1955
1956 /*
1957 for(int i = 1;i<desfuture.size();i++){
1958 auto& fut = desfuture[i];
1959 if (fut.valid()){
1960 fut.get();
1961
1962 }
1963 i++;
1964 };
1965 */
1966
1967
1968 };
uint32_t consume
Definition: SignalVk.h:30
uint32_t produce
Definition: SignalVk.h:31
bonqueue< uint32_t, 1000000 > buds
Definition: AllocatorVk.h:1756

◆ Dispatch()

void front::DeallocatorVk::Dispatch ( )

Definition at line 1843 of file AllocatorVk.cpp.

1843 {
1844
1845 if (!PyEval_ThreadsInitialized())
1846 {
1847 PyEval_InitThreads();
1848 }
1849
1850#if LBSTA == 0
1851 InitializeCriticalSectionAndSpinCount(&killer.sectAlloc, 8000);
1852 AllocKiller(0, 100);
1853#else
1854 killer.size = (ssize_t)LBSTA;
1855#endif
1856 buds.reset();
1857 desfuture.clear();
1858 killer.idx = 0;
1859 nib_end.store(false);
1860 printf(" killer dispatch occupa %zd size %zd \n", desType::Occupa(),killer.size);
1861
1862
1863 uint32_t fid = AllocFuture();
1864 desfuture[fid] = std::move(std::async(std::launch::async, &DeallocatorVk::NipInTheBud, this));
1865
1866 };
#define LBSTA
Definition: AllocatorVk.h:1722
void reset()
Definition: SignalVk.h:33
bool AllocKiller(ssize_t idx, ssize_t reserve)
std::atomic_bool nib_end
Definition: AllocatorVk.h:1755

◆ Holocaust()

void front::DeallocatorVk::Holocaust ( )

log_allo("Call kill %zu \n", idx);

Definition at line 1970 of file AllocatorVk.cpp.

1970 {
1971
1972
1973 $DSL.destroy();
1974
1975
1976 if (!nib_end.load() && desfuture.size() > 0) {
1977
1978
1979 ClearBuds();
1980
1981 nib_end.store(true);
1982 buds.push(0);
1983
1984 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1985
1986 uint32_t fin = buds.nip();
1987 if (!(fin == 12345 || fin == 0) ){
1988 log_bad("Nip Not at All Buds. total %u fin %u last %u \n", _total, fin, budsNums.load());
1989 }
1990
1991
1992 }
1993
1994
1995 if (killer.size > 0) {
1996 ssize_t N = (killer.size > killer.idx) ? killer.idx : killer.size;
1997 for (ssize_t idx = 0; idx < N; idx++) {
1999 if (!KillForce(idx)) {
2000 log_bad("killer failed to kill.\n");
2001 };
2002 }
2003 }
2004
2005 for (auto& [k, th] : beginThreads) {
2006 log_info("Holocaust Close Threads %s \n", k.c_str());
2007 CloseHandle(th);
2008 };
2009
2010#if LBSTA == 0
2011 delete[] killer._;
2012 killer._ = nullptr;
2013 killer.size = 0;
2014 if (sectAlloc.OwningThread != nullptr) {
2015 log_allo("Delete SectionAlloc this %p \n", sectAlloc.OwningThread);
2016 DeleteCriticalSection(&sectAlloc);
2017 sectAlloc.OwningThread = nullptr;
2018 };
2019
2020#endif
2021
2022 };
void push(T val)
Definition: SignalVk.h:43
#define log_info(...)
Definition: log.hpp:34
std::unordered_map< std::string, HANDLE > beginThreads
Definition: AllocatorVk.h:1751
bool KillForce(ssize_t idx)
Definition: AllocatorVk.h:1826

◆ Kill()

bool front::DeallocatorVk::Kill ( ssize_t  ID)
inline

Definition at line 1815 of file AllocatorVk.h.

1815 {
1816
1817 ssize_t idx = ID % killer.size;
1818 if (killer._[idx] == ID) {
1819 bool ret = !killer._[idx](true);
1820 if (ret)killer._[idx].Delete();
1821 return ret;
1822 }
1823 return true;
1824
1825 };

◆ KillForce()

bool front::DeallocatorVk::KillForce ( ssize_t  idx)
inline

Definition at line 1826 of file AllocatorVk.h.

1826 {
1827
1828
1829 if (killer._[idx]) {
1830 bool ret = !killer._[idx](true);
1831 if(ret)killer._[idx].Delete();
1832 return ret;
1833 }
1834 return true;
1835 };

◆ NipInTheBud()

bool front::DeallocatorVk::NipInTheBud ( )

Definition at line 1868 of file AllocatorVk.cpp.

1868 {
1869
1870
1871 while (!nib_end.load()) {
1872
1873 uint32_t idx = buds.nip();
1874 {
1875 const std::lock_guard<std::mutex> lock(mtx_desfuture);
1876 if (idx == uint32_t(-1)) {
1877 _total++;
1878 }
1879 else {
1880 if (idx != 0 && desfuture[idx].valid()) {
1881 bool res = desfuture[idx].get();
1882 if (!res) {
1883 log_warning("you dont know whether or not nip in the bud.");
1884 };
1885 }
1886 _total++;
1887 budsNums.store(budsNums - 1);
1888 }
1889 }
1890 };
1891
1892 log_debug("Nip in the Bud Ternimate. %u <> %u size % zu \n", _total, budsNums.load(), desfuture.size());
1893 buds.push(12345);
1894 return true;
1895
1896 };
#define log_warning(...)
Definition: log.hpp:35
#define log_debug(...)
Definition: log.hpp:27

◆ ToDoList()

template<class F >
ssize_t front::DeallocatorVk::ToDoList ( F const &  f,
ssize_t  reserve = 100 
)
inline

occupa = desType::Occupa();

Definition at line 1772 of file AllocatorVk.h.

1773 {
1774
1775
1776 ssize_t ID = 0;
1777
1778 ssize_t idx = 0;
1779
1780#if LBSTA == 0
1781 size = InterlockedAdd64((LONG64*)&killer.size, 0);
1782 if (idx >= size * 2 / 3) {
1784 };
1785#else
1787 ssize_t cnt = 0;
1788 while(++cnt < killer.size) {
1789 ID = InterlockedIncrement64((LONG64*)&killer.idx) - 1;
1790 idx = ID % killer.size;
1791 if(!killer._[idx]) {
1792 killer._[idx].copy(f, ID);
1793 if (killer._[idx](false)) return ID;
1794 return -1;
1795 }
1796 };
1797
1798#endif
1799
1800
1801 return -1;
1802
1803 };

Member Data Documentation

◆ _

desType front::DeallocatorVk::_[LBSTA]

std::vector<desType > _;

Definition at line 1742 of file AllocatorVk.h.

◆ _total

uint32_t front::DeallocatorVk::_total = 0

Definition at line 1759 of file AllocatorVk.h.

◆ beginThreads

std::unordered_map<std::string, HANDLE> front::DeallocatorVk::beginThreads

Definition at line 1751 of file AllocatorVk.h.

◆ buds

bonqueue<uint32_t, 1000000> front::DeallocatorVk::buds

Definition at line 1756 of file AllocatorVk.h.

◆ budsNums

std::atomic_uint front::DeallocatorVk::budsNums = { 0 }

Definition at line 1757 of file AllocatorVk.h.

◆ desfuture

std::vector<std::future<futType> > front::DeallocatorVk::desfuture

Definition at line 1752 of file AllocatorVk.h.

◆ idx

ssize_t front::DeallocatorVk::idx = 0

Definition at line 1745 of file AllocatorVk.h.

◆ mtx_desfuture

std::mutex front::DeallocatorVk::mtx_desfuture

Definition at line 1753 of file AllocatorVk.h.

◆ nib_end

std::atomic_bool front::DeallocatorVk::nib_end

Definition at line 1755 of file AllocatorVk.h.

◆ size

ssize_t front::DeallocatorVk::size = 0

Definition at line 1746 of file AllocatorVk.h.


The documentation for this struct was generated from the following files: