Skip to content

Commit 51c0dde

Browse files
Merge pull request #472 from qubic/develop (Release v1.250.0)
Release v1.250.0
2 parents a19ecc5 + d964253 commit 51c0dde

File tree

10 files changed

+109
-61
lines changed

10 files changed

+109
-61
lines changed

src/common_buffers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "network_messages/assets.h"
88

99

10-
constexpr unsigned long long spectrumSizeInBytes = SPECTRUM_CAPACITY * sizeof(::Entity);
10+
constexpr unsigned long long spectrumSizeInBytes = SPECTRUM_CAPACITY * sizeof(EntityRecord);
1111
constexpr unsigned long long universeSizeInBytes = ASSETS_CAPACITY * sizeof(AssetRecord);
1212
// TODO: check that max contract state size does not exceed size of spectrum or universe
1313
constexpr unsigned long long reorgBufferSize = (spectrumSizeInBytes >= universeSizeInBytes) ? spectrumSizeInBytes : universeSizeInBytes;

src/contracts/QVAULT.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ struct QVAULT : public ContractBase
604604

605605
struct END_EPOCH_locals
606606
{
607-
::Entity entity;
607+
Entity entity;
608608
AssetPossessionIterator iter;
609609
Asset QCAPId;
610610
uint64 revenue;

src/contracts/Qearn.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ struct QEARN : public ContractBase
318318

319319
struct getStatsPerEpoch_locals
320320
{
321-
::Entity entity;
321+
Entity entity;
322322
uint32 cnt, _t;
323323
};
324324

@@ -900,7 +900,7 @@ struct QEARN : public ContractBase
900900
bit status;
901901
uint64 pre_epoch_balance;
902902
uint64 current_balance;
903-
::Entity entity;
903+
Entity entity;
904904
uint32 locked_epoch;
905905
};
906906

src/network_messages/entity.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "common_def.h"
44

5-
struct Entity
5+
struct EntityRecord
66
{
77
m256i publicKey;
88
long long incomingAmount, outgoingAmount;
@@ -13,7 +13,7 @@ struct Entity
1313
unsigned int latestIncomingTransferTick, latestOutgoingTransferTick;
1414
};
1515

16-
static_assert(sizeof(::Entity) == 32 + 2 * 8 + 2 * 4 + 2 * 4, "Something is wrong with the struct size.");
16+
static_assert(sizeof(EntityRecord) == 32 + 2 * 8 + 2 * 4 + 2 * 4, "Something is wrong with the struct size.");
1717

1818

1919
#define REQUEST_ENTITY 31
@@ -30,10 +30,10 @@ static_assert(sizeof(RequestedEntity) == 32, "Something is wrong with the struct
3030

3131
struct RespondedEntity
3232
{
33-
::Entity entity;
33+
EntityRecord entity;
3434
unsigned int tick;
3535
int spectrumIndex;
3636
m256i siblings[SPECTRUM_DEPTH];
3737
};
3838

39-
static_assert(sizeof(RespondedEntity) == sizeof(::Entity) + 4 + 4 + 32 * SPECTRUM_DEPTH, "Something is wrong with the struct size.");
39+
static_assert(sizeof(RespondedEntity) == sizeof(EntityRecord) + 4 + 4 + 32 * SPECTRUM_DEPTH, "Something is wrong with the struct size.");

src/public_settings.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ static_assert(AUTO_FORCE_NEXT_TICK_THRESHOLD* TARGET_TICK_DURATION >= PEER_REFRE
5656
// Config options that should NOT be changed by operators
5757

5858
#define VERSION_A 1
59-
#define VERSION_B 249
60-
#define VERSION_C 1
59+
#define VERSION_B 250
60+
#define VERSION_C 0
6161

6262
// Epoch and initial tick for node startup
63-
#define EPOCH 168
64-
#define TICK 28376000
63+
#define EPOCH 169
64+
#define TICK 29000000
6565

6666
#define ARBITRATOR "AFZPUAIYVPNUYGJRQVLUKOPPVLHAZQTGLYAAUUNBXFTVTAMSBKQBLEIEPCVJ"
6767
#define DISPATCHER "XPXYKFLGSWRHRGAUKWFWVXCDVEYAPCPCNUTMUDWFGDYQCWZNJMWFZEEGCFFO"
@@ -75,19 +75,19 @@ static unsigned short CONTRACT_FILE_NAME[] = L"contract????.???";
7575
static unsigned short CUSTOM_MINING_REVENUE_END_OF_EPOCH_FILE_NAME[] = L"custom_revenue.eoe";
7676
static unsigned short CUSTOM_MINING_CACHE_FILE_NAME[] = L"custom_mining_cache???.???";
7777

78-
static constexpr unsigned long long NUMBER_OF_INPUT_NEURONS = 256; // K
79-
static constexpr unsigned long long NUMBER_OF_OUTPUT_NEURONS = 256; // L
80-
static constexpr unsigned long long NUMBER_OF_TICKS = 120; // N
81-
static constexpr unsigned long long NUMBER_OF_NEIGHBORS = 256; // 2M. Must be divided by 2
82-
static constexpr unsigned long long NUMBER_OF_MUTATIONS = 100;
78+
static constexpr unsigned long long NUMBER_OF_INPUT_NEURONS = 512; // K
79+
static constexpr unsigned long long NUMBER_OF_OUTPUT_NEURONS = 512; // L
80+
static constexpr unsigned long long NUMBER_OF_TICKS = 200; // N
81+
static constexpr unsigned long long NUMBER_OF_NEIGHBORS = 728; // 2M. Must be divided by 2
82+
static constexpr unsigned long long NUMBER_OF_MUTATIONS = 150;
8383
static constexpr unsigned long long POPULATION_THRESHOLD = NUMBER_OF_INPUT_NEURONS + NUMBER_OF_OUTPUT_NEURONS + NUMBER_OF_MUTATIONS; // P
8484
static constexpr long long NEURON_VALUE_LIMIT = 1LL;
85-
static constexpr unsigned int SOLUTION_THRESHOLD_DEFAULT = 178;
85+
static constexpr unsigned int SOLUTION_THRESHOLD_DEFAULT = 321;
8686

8787
#define SOLUTION_SECURITY_DEPOSIT 1000000
8888

8989
// Signing difficulty
90-
#define TARGET_TICK_VOTE_SIGNATURE 0x000CFFFFU // around 5000 signing operations per ID
90+
#define TARGET_TICK_VOTE_SIGNATURE 0x00095CBEU // around 7000 signing operations per ID
9191

9292
// include commonly needed definitions
9393
#include "network_messages/common_def.h"

src/qubic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ static void processRequestEntity(Peer* peer, RequestResponseHeader* header)
12651265
}
12661266
else
12671267
{
1268-
copyMem(&respondedEntity.entity, &spectrum[respondedEntity.spectrumIndex], sizeof(::Entity));
1268+
copyMem(&respondedEntity.entity, &spectrum[respondedEntity.spectrumIndex], sizeof(EntityRecord));
12691269
ACQUIRE(spectrumLock);
12701270
getSiblings<SPECTRUM_DEPTH>(respondedEntity.spectrumIndex, spectrumDigests, respondedEntity.siblings);
12711271
RELEASE(spectrumLock);
@@ -5520,7 +5520,7 @@ static bool initialize()
55205520
numberOfLeafs >>= 1;
55215521
}
55225522

5523-
setNumber(message, SPECTRUM_CAPACITY * sizeof(::Entity), TRUE);
5523+
setNumber(message, SPECTRUM_CAPACITY * sizeof(EntityRecord), TRUE);
55245524
appendText(message, L" bytes of the spectrum data are hashed (");
55255525
appendNumber(message, (__rdtsc() - beginningTick) * 1000000 / frequency, TRUE);
55265526
appendText(message, L" microseconds).");

src/score.h

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ struct ScoreFunction
146146
static constexpr unsigned long long maxNumberOfSynapses = populationThreshold * numberOfNeighbors;
147147
static constexpr unsigned long long initNumberOfSynapses = numberOfNeurons * numberOfNeighbors;
148148
static constexpr long long radius = (long long)numberOfNeighbors / 2;
149-
static constexpr long long paddingNeuronsCount = maxNumberOfNeurons + numberOfNeighbors;
149+
static constexpr long long paddingNeuronsCount = (maxNumberOfNeurons + numberOfNeighbors + BATCH_SIZE - 1) / BATCH_SIZE * BATCH_SIZE;
150+
static constexpr long long incommingSynapsesPitch = (numberOfNeighbors + 1 + BATCH_SIZE - 1) / BATCH_SIZE * BATCH_SIZE;
150151

151152
static_assert(numberOfInputNeurons % 64 == 0, "numberOfInputNeurons must be divided by 64");
152153
static_assert(numberOfOutputNeurons % 64 == 0, "numberOfOutputNeurons must be divided by 64");
@@ -216,7 +217,8 @@ struct ScoreFunction
216217

217218
Neuron* neurons;
218219
// Padding start and end of neurons so that we can reduce the condition checking
219-
Neuron paddingNeurons[maxNumberOfNeurons + numberOfNeighbors];
220+
// Also padding at the end so that is divided by BATCH_SIZE
221+
Neuron paddingNeurons[paddingNeuronsCount];
220222
NeuronType neuronTypes[maxNumberOfNeurons];
221223
Synapse synapses[maxNumberOfSynapses];
222224

@@ -241,8 +243,7 @@ struct ScoreFunction
241243
unsigned long long removalNeuronsCount;
242244

243245
// Contain incomming synapse of neurons. The center one will be zeros
244-
Synapse incommingSynapses[maxNumberOfSynapses + maxNumberOfNeurons];
245-
246+
Synapse incommingSynapses[maxNumberOfNeurons * incommingSynapsesPitch];
246247

247248
void mutate(unsigned long long mutateStep)
248249
{
@@ -596,15 +597,14 @@ struct ScoreFunction
596597
setMem(neuronValueBuffer, sizeof(neuronValueBuffer), 0);
597598
Neuron* pPaddingNeurons = currentANN.paddingNeurons;
598599
Synapse* synapses = incommingSynapses;
599-
Neuron* neurons = currentANN.neurons;
600600

601-
for (unsigned long long n = 0; n < population; ++n, pPaddingNeurons++, synapses += (numberOfNeighbors + 1))
601+
for (unsigned long long n = 0; n < population; ++n, pPaddingNeurons++, synapses += incommingSynapsesPitch)
602602
{
603603
int neuronValue = 0;
604-
long long m = 0;
605604
#if defined (__AVX512F__)
606605
const __m512i zeros512 = _mm512_setzero_si512();
607-
for (; m + BATCH_SIZE <= numberOfNeighbors; m += BATCH_SIZE)
606+
const __m512i allOnes512 = _mm512_set1_epi8(char(-1));
607+
for (long long m = 0; m < incommingSynapsesPitch; m += BATCH_SIZE)
608608
{
609609
const __m512i neurons512 = _mm512_loadu_si512((const __m512i*)(pPaddingNeurons + m));
610610
const __m512i synapses512 = _mm512_loadu_si512((const __m512i*)(synapses + m));
@@ -622,7 +622,7 @@ struct ScoreFunction
622622
const __m256i allOnes256 = _mm256_set1_epi8(-1);
623623
unsigned int negMask = 0;
624624
unsigned int posMask = 0;
625-
for (; m + BATCH_SIZE <= numberOfNeighbors; m += BATCH_SIZE)
625+
for (long long m = 0; m < incommingSynapsesPitch; m += BATCH_SIZE)
626626
{
627627
const __m256i neurons256 = _mm256_loadu_si256((const __m256i*)(pPaddingNeurons + m));
628628
const __m256i synapses256 = _mm256_loadu_si256((const __m256i*)(synapses + m));
@@ -642,20 +642,10 @@ struct ScoreFunction
642642
}
643643

644644
#endif
645-
646-
for (; m <= numberOfNeighbors; ++m)
647-
{
648-
const Synapse synapseWeight = synapses[m];
649-
const Neuron nVal = pPaddingNeurons[m];
650-
651-
// Weight-sum
652-
neuronValue += synapseWeight * nVal;
653-
}
654-
655645
neuronValueBuffer[n] = (Neuron)clampNeuron(neuronValue);
656646
}
657647

658-
copyMem(neurons, neuronValueBuffer, population * sizeof(Neuron));
648+
copyMem(currentANN.neurons, neuronValueBuffer, population * sizeof(Neuron));
659649
}
660650

661651
void runTickSimulation()
@@ -682,18 +672,19 @@ struct ScoreFunction
682672
for (long long m = 0; m < radius; m++)
683673
{
684674
Synapse synapseWeight = kSynapses[m];
685-
unsigned long long nnIndex = clampNeuronIndex(n + m, -(long long)numberOfNeighbors / 2);
686-
incommingSynapses[nnIndex * (numberOfNeighbors + 1) + (numberOfNeighbors - m)] = synapseWeight; // need to pad 1
675+
unsigned long long nnIndex = clampNeuronIndex(n + m, -radius);
676+
incommingSynapses[nnIndex * incommingSynapsesPitch + (numberOfNeighbors - m)] = synapseWeight;
687677
}
688678

689-
incommingSynapses[n * (numberOfNeighbors + 1) + radius] = 0;
690-
691679
for (long long m = radius; m < numberOfNeighbors; m++)
692680
{
693681
Synapse synapseWeight = kSynapses[m];
694-
unsigned long long nnIndex = clampNeuronIndex(n + m + 1, -(long long)numberOfNeighbors / 2);
695-
incommingSynapses[nnIndex * (numberOfNeighbors + 1) + (numberOfNeighbors - m - 1)] = synapseWeight;
682+
unsigned long long nnIndex = clampNeuronIndex(n + m + 1, -radius);
683+
incommingSynapses[nnIndex * incommingSynapsesPitch + (numberOfNeighbors - m - 1)] = synapseWeight;
696684
}
685+
686+
// Self incomming synapse is set as zero
687+
incommingSynapses[n * incommingSynapsesPitch + radius] = 0;
697688
}
698689

699690
for (unsigned long long tick = 0; tick < numberOfTicks; ++tick)
@@ -872,6 +863,7 @@ struct ScoreFunction
872863
Neuron* neurons = currentANN.neurons;
873864
InitValue* initValue = (InitValue*)paddingInitValue;
874865

866+
875867
// Initialization
876868
population = numberOfNeurons;
877869
removalNeuronsCount = 0;
@@ -1000,6 +992,8 @@ struct ScoreFunction
1000992
bool initMemory()
1001993
{
1002994
random2PoolLock = 0;
995+
996+
// Make sure all padding data is set as zeros
1003997
setMem(_computeBuffer, sizeof(_computeBuffer), 0);
1004998

1005999
for (int i = 0; i < solutionBufferCount; i++)

src/spectrum/spectrum.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "common_buffers.h"
1919

2020
GLOBAL_VAR_DECL volatile char spectrumLock GLOBAL_VAR_INIT(0);
21-
GLOBAL_VAR_DECL ::Entity* spectrum GLOBAL_VAR_INIT(nullptr);
21+
GLOBAL_VAR_DECL EntityRecord* spectrum GLOBAL_VAR_INIT(nullptr);
2222
GLOBAL_VAR_DECL struct SpectrumInfo {
2323
unsigned int numberOfEntities = 0; // Number of entities in the spectrum hash map, may include entries with balance == 0
2424
unsigned long long totalAmount = 0; // Total amount of qubics in the spectrum
@@ -149,8 +149,8 @@ static void reorganizeSpectrum()
149149

150150
unsigned long long spectrumReorgStartTick = __rdtsc();
151151

152-
::Entity* reorgSpectrum = (::Entity*)reorgBuffer;
153-
setMem(reorgSpectrum, SPECTRUM_CAPACITY * sizeof(::Entity), 0);
152+
EntityRecord* reorgSpectrum = (EntityRecord*)reorgBuffer;
153+
setMem(reorgSpectrum, SPECTRUM_CAPACITY * sizeof(EntityRecord), 0);
154154
for (unsigned int i = 0; i < SPECTRUM_CAPACITY; i++)
155155
{
156156
if (spectrum[i].incomingAmount - spectrum[i].outgoingAmount)
@@ -160,7 +160,7 @@ static void reorganizeSpectrum()
160160
iteration:
161161
if (isZero(reorgSpectrum[index].publicKey))
162162
{
163-
copyMem(&reorgSpectrum[index], &spectrum[i], sizeof(::Entity));
163+
copyMem(&reorgSpectrum[index], &spectrum[i], sizeof(EntityRecord));
164164
}
165165
else
166166
{
@@ -170,7 +170,7 @@ static void reorganizeSpectrum()
170170
}
171171
}
172172
}
173-
copyMem(spectrum, reorgSpectrum, SPECTRUM_CAPACITY * sizeof(::Entity));
173+
copyMem(spectrum, reorgSpectrum, SPECTRUM_CAPACITY * sizeof(EntityRecord));
174174

175175
unsigned int digestIndex;
176176
for (digestIndex = 0; digestIndex < SPECTRUM_CAPACITY; digestIndex++)
@@ -380,8 +380,8 @@ static bool decreaseEnergy(const int index, long long amount)
380380
static bool loadSpectrum(const CHAR16* fileName = SPECTRUM_FILE_NAME, const CHAR16* directory = nullptr)
381381
{
382382
logToConsole(L"Loading spectrum file ...");
383-
long long loadedSize = load(fileName, SPECTRUM_CAPACITY * sizeof(::Entity), (unsigned char*)spectrum, directory);
384-
if (loadedSize != SPECTRUM_CAPACITY * sizeof(::Entity))
383+
long long loadedSize = load(fileName, SPECTRUM_CAPACITY * sizeof(EntityRecord), (unsigned char*)spectrum, directory);
384+
if (loadedSize != SPECTRUM_CAPACITY * sizeof(EntityRecord))
385385
{
386386
logStatusToConsole(L"EFI_FILE_PROTOCOL.Read() reads invalid number of bytes", loadedSize, __LINE__);
387387

@@ -398,10 +398,10 @@ static bool saveSpectrum(const CHAR16* fileName = SPECTRUM_FILE_NAME, const CHAR
398398
const unsigned long long beginningTick = __rdtsc();
399399

400400
ACQUIRE(spectrumLock);
401-
long long savedSize = save(fileName, SPECTRUM_CAPACITY * sizeof(::Entity), (unsigned char*)spectrum, directory);
401+
long long savedSize = save(fileName, SPECTRUM_CAPACITY * sizeof(EntityRecord), (unsigned char*)spectrum, directory);
402402
RELEASE(spectrumLock);
403403

404-
if (savedSize == SPECTRUM_CAPACITY * sizeof(::Entity))
404+
if (savedSize == SPECTRUM_CAPACITY * sizeof(EntityRecord))
405405
{
406406
setNumber(message, savedSize, TRUE);
407407
appendText(message, L" bytes of the spectrum data are saved (");

test/score.cpp

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,31 @@ void runCommonTests()
196196
ASSERT_FALSE(scoresString.empty());
197197

198198
// Convert the raw string and do the data verification
199-
unsigned long long numberOfSamples = sampleString.size();
199+
unsigned long long numberOfSamplesReadFromFile = sampleString.size();
200+
unsigned long long numberOfSamples = numberOfSamplesReadFromFile;
200201
if (COMMON_TEST_NUMBER_OF_SAMPLES > 0)
201202
{
203+
std::cout << "Request testing with " << COMMON_TEST_NUMBER_OF_SAMPLES << " samples." << std::endl;
204+
202205
numberOfSamples = std::min(COMMON_TEST_NUMBER_OF_SAMPLES, numberOfSamples);
206+
if (COMMON_TEST_NUMBER_OF_SAMPLES <= numberOfSamples)
207+
{
208+
numberOfSamples = COMMON_TEST_NUMBER_OF_SAMPLES;
209+
}
210+
else // Request number of samples greater than existed. Only valid for reference score validation only
211+
{
212+
if (gCompareReference)
213+
{
214+
numberOfSamples = COMMON_TEST_NUMBER_OF_SAMPLES;
215+
std::cout << "Refenrece comparison mode: " << numberOfSamples << " samples are read from file for comparision."
216+
<< "Remained are generated randomly."
217+
<< std::endl;
218+
}
219+
else
220+
{
221+
std::cout << "Only " << numberOfSamples << " samples can be read from file for comparison" << std::endl;
222+
}
223+
}
203224
}
204225

205226
std::vector<m256i> miningSeeds(numberOfSamples);
@@ -209,9 +230,30 @@ void runCommonTests()
209230
// Reading the input samples
210231
for (unsigned long long i = 0; i < numberOfSamples; ++i)
211232
{
212-
miningSeeds[i] = hexToByte(sampleString[i][0], 32);
213-
publicKeys[i] = hexToByte(sampleString[i][1], 32);
214-
nonces[i] = hexToByte(sampleString[i][2], 32);
233+
if (i < numberOfSamplesReadFromFile)
234+
{
235+
miningSeeds[i] = hexToByte(sampleString[i][0], 32);
236+
publicKeys[i] = hexToByte(sampleString[i][1], 32);
237+
nonces[i] = hexToByte(sampleString[i][2], 32);
238+
}
239+
else // Samples from files are not enough, randomly generate more
240+
{
241+
_rdrand64_step((unsigned long long*) & miningSeeds[i].m256i_u8[0]);
242+
_rdrand64_step((unsigned long long*) & miningSeeds[i].m256i_u8[8]);
243+
_rdrand64_step((unsigned long long*) & miningSeeds[i].m256i_u8[16]);
244+
_rdrand64_step((unsigned long long*) & miningSeeds[i].m256i_u8[24]);
245+
246+
_rdrand64_step((unsigned long long*) & publicKeys[i].m256i_u8[0]);
247+
_rdrand64_step((unsigned long long*) & publicKeys[i].m256i_u8[8]);
248+
_rdrand64_step((unsigned long long*) & publicKeys[i].m256i_u8[16]);
249+
_rdrand64_step((unsigned long long*) & publicKeys[i].m256i_u8[24]);
250+
251+
_rdrand64_step((unsigned long long*) & nonces[i].m256i_u8[0]);
252+
_rdrand64_step((unsigned long long*) & nonces[i].m256i_u8[8]);
253+
_rdrand64_step((unsigned long long*) & nonces[i].m256i_u8[16]);
254+
_rdrand64_step((unsigned long long*) & nonces[i].m256i_u8[24]);
255+
256+
}
215257
}
216258

217259
// Reading the header of score and verification
@@ -314,7 +356,17 @@ void runCommonTests()
314356
samples.push_back(i);
315357
}
316358

317-
std::cout << "Processing " << samples.size() << " samples ..." << std::endl;
359+
std::string compTerm = " and compare with groundtruths from file.";
360+
if (gCompareReference)
361+
{
362+
compTerm = " and compare with reference code.";
363+
}
364+
if (ENABLE_PROFILING)
365+
{
366+
compTerm = "for profiling, without comparing any result (set test case FAILED as default)";
367+
}
368+
369+
std::cout << "Processing " << samples.size() << " samples " << compTerm << "..." << std::endl;
318370
#pragma omp parallel for num_threads(numberOfThreads)
319371
for (int i = 0; i < samples.size(); ++i)
320372
{

0 commit comments

Comments
 (0)