@@ -12,8 +12,6 @@ using namespace core;
12
12
13
13
#define kHardwareInstancesTOTAL (kNumHardwareInstancesX *kNumHardwareInstancesY *kNumHardwareInstancesZ )
14
14
15
-
16
- // !Same As Last Example
17
15
class MyEventReceiver : public IEventReceiver
18
16
{
19
17
public:
@@ -42,8 +40,8 @@ class MyEventReceiver : public IEventReceiver
42
40
private:
43
41
};
44
42
45
- constexpr size_t minTestsCnt = 10000u ;
46
- constexpr size_t maxTestsCnt = 20000u ;
43
+ constexpr size_t minTestsCnt = 100u ;
44
+ constexpr size_t maxTestsCnt = 200u ;
47
45
constexpr size_t maxAlignmentExp = 12u ; // 4096
48
46
constexpr size_t minVirtualMemoryBufferSize = 2048 ; // 2kB
49
47
constexpr size_t maxVirtualMemoryBufferSize = 2147483648 ; // 2GB
@@ -89,9 +87,32 @@ class AllocatorHandler
89
87
public:
90
88
void executeAllocatorTest ()
91
89
{
92
- const uint32_t testsCnt = rng.getRndAllocCnt ();
93
- for (size_t i = 0 ; i < testsCnt; ++i)
94
- executeForFrame ();
90
+ uint32_t testsCnt = rng.getRndAllocCnt ();
91
+
92
+ for (size_t i = 0 ; i < testsCnt; i++)
93
+ {
94
+ AlctrType alctr;
95
+ RandParams randAllocParams = getRandParams ();
96
+ void * reservedSpace = nullptr ;
97
+
98
+ if constexpr (std::is_same<AlctrType, core::LinearAddressAllocator<uint32_t >>::value)
99
+ {
100
+ alctr = AlctrType (nullptr , randAllocParams.offset , randAllocParams.alignOffset , randAllocParams.maxAlign , randAllocParams.addressSpaceSize );
101
+ }
102
+ else
103
+ {
104
+ const auto reservedSize = AlctrType::reserved_size (randAllocParams.maxAlign , randAllocParams.addressSpaceSize , randAllocParams.blockSz );
105
+ reservedSpace = _NBL_ALIGNED_MALLOC (reservedSize, _NBL_SIMD_ALIGNMENT);
106
+ alctr = AlctrType (reservedSpace, randAllocParams.offset , randAllocParams.alignOffset , randAllocParams.maxAlign , randAllocParams.addressSpaceSize , randAllocParams.blockSz );
107
+ }
108
+
109
+ testsCnt = rng.getRndAllocCnt ();
110
+ for (size_t i = 0 ; i < testsCnt; i++)
111
+ executeForFrame (alctr, randAllocParams);
112
+
113
+ if constexpr (!std::is_same<AlctrType, core::LinearAddressAllocator<uint32_t >>::value)
114
+ _NBL_ALIGNED_FREE (reservedSpace);
115
+ }
95
116
}
96
117
97
118
private:
@@ -112,23 +133,8 @@ class AllocatorHandler
112
133
};
113
134
114
135
private:
115
- void executeForFrame ()
136
+ void executeForFrame (AlctrType& alctr, RandParams& randAllocParams )
116
137
{
117
- RandParams randAllocParams = getRandParams ();
118
- void * reservedSpace = nullptr ;
119
- AlctrType alctr;
120
-
121
- if constexpr (std::is_same<AlctrType, core::LinearAddressAllocator<uint32_t >>::value)
122
- {
123
- alctr = AlctrType (nullptr , randAllocParams.offset , randAllocParams.alignOffset , randAllocParams.maxAlign , randAllocParams.addressSpaceSize );
124
- }
125
- else
126
- {
127
- const auto reservedSize = AlctrType::reserved_size (randAllocParams.maxAlign , randAllocParams.addressSpaceSize , randAllocParams.blockSz );
128
- reservedSpace = _NBL_ALIGNED_MALLOC (reservedSize, _NBL_SIMD_ALIGNMENT);
129
- alctr = AlctrType (reservedSpace, randAllocParams.offset , randAllocParams.alignOffset , randAllocParams.maxAlign , randAllocParams.addressSpaceSize , randAllocParams.blockSz );
130
- }
131
-
132
138
// randomly decide how many `multi_allocs` to do
133
139
const uint32_t multiAllocCnt = rng.getRandomNumber (1u , 500u );
134
140
for (uint32_t i = 0u ; i < multiAllocCnt; i++)
@@ -166,10 +172,11 @@ class AllocatorHandler
166
172
randFreeAllocatedAddresses (alctr);
167
173
}
168
174
}
169
-
170
- if constexpr (!std::is_same<AlctrType, core::LinearAddressAllocator<uint32_t >>::value)
171
- _NBL_ALIGNED_FREE (reservedSpace);
172
-
175
+ else
176
+ {
177
+ alctr.reset ();
178
+ results.clear ();
179
+ }
173
180
}
174
181
175
182
// random dealloc function
@@ -284,13 +291,18 @@ class AllocatorHandler
284
291
template <>
285
292
void AllocatorHandler<core::LinearAddressAllocator<uint32_t >>::randFreeAllocatedAddresses(core::LinearAddressAllocator<uint32_t >& alctr)
286
293
{
287
- alctr.reset ();
288
- results.clear ();
294
+ const bool performReset = rng.getRandomNumber (1 , 10 ) == 1 ? true : false ;
295
+
296
+ if (performReset)
297
+ {
298
+ alctr.reset ();
299
+ results.clear ();
300
+ }
289
301
}
290
302
291
303
int main ()
292
304
{
293
-
305
+
294
306
// Allocator test
295
307
{
296
308
{
0 commit comments