Monero
Loading...
Searching...
No Matches
dataset.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2018-2019, tevador <tevador@gmail.com>
3
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of the copyright holder nor the
14 names of its contributors may be used to endorse or promote products
15 derived from this software without specific prior written permission.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29#pragma once
30
31#include <cstdint>
32#include <vector>
33#include <type_traits>
34#include "common.hpp"
36#include "allocator.hpp"
37#include "argon2.h"
38
39/* Global scope for C binding */
41 uint8_t* memory = nullptr;
43};
44
45/* Global scope for C binding */
47 uint8_t* memory = nullptr;
53 std::vector<uint64_t> reciprocalCache;
54 std::string cacheKey;
56
58 return programs[0].getSize() != 0;
59 }
60};
61
62//A pointer to a standard-layout struct object points to its initial member
63static_assert(std::is_standard_layout<randomx_dataset>(), "randomx_dataset must be a standard-layout struct");
64
65//the following assert fails when compiling Debug in Visual Studio (JIT mode will crash in Debug)
66#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && defined(_DEBUG)
67#define TO_STR(x) #x
68#define STR(x) TO_STR(x)
69#pragma message ( __FILE__ "(" STR(__LINE__) ") warning: check std::is_standard_layout<randomx_cache>() is disabled for Debug configuration. JIT mode will crash." )
70#undef STR
71#undef TO_STR
72#else
73static_assert(std::is_standard_layout<randomx_cache>(), "randomx_cache must be a standard-layout struct");
74#endif
75
76namespace randomx {
77
79
80 template<class Allocator>
82 if (dataset->memory != nullptr)
83 Allocator::freeMemory(dataset->memory, DatasetSize);
84 }
85
86 template<class Allocator>
88
89 void initCache(randomx_cache*, const void*, size_t);
90 void initCacheCompile(randomx_cache*, const void*, size_t);
91 void initDatasetItem(randomx_cache* cache, uint8_t* out, uint64_t blockNumber);
92 void initDataset(randomx_cache* cache, uint8_t* dataset, uint32_t startBlock, uint32_t endBlock);
93
97 }
100 }
102 }
103}
void randomx_argon2_fill_segment_ref(const argon2_instance_t *instance, argon2_position_t position)
Definition: argon2_ref.c:110
randomx_argon2_impl * randomx_argon2_impl_ssse3()
Definition: argon2_ssse3.c:48
void randomx_argon2_impl(const argon2_instance_t *instance, argon2_position_t position)
Definition: argon2.h:238
randomx_argon2_impl * randomx_argon2_impl_avx2()
Definition: argon2_avx2.c:44
Definition: jit_compiler_fallback.hpp:42
Definition: superscalar_program.hpp:37
uint32_t getSize()
Definition: superscalar_program.hpp:46
#define RANDOMX_CACHE_ACCESSES
Definition: configuration.h:44
static int flags
Definition: mdb_load.c:31
Definition: allocator.cpp:35
randomx_argon2_impl * selectArgonImpl(randomx_flags flags)
Definition: dataset.hpp:94
void() DatasetInitFunc(randomx_cache *cache, uint8_t *dataset, uint32_t startBlock, uint32_t endBlock)
Definition: common.hpp:182
void initCache(randomx_cache *cache, const void *key, size_t keySize)
Definition: dataset.cpp:71
void deallocDataset(randomx_dataset *dataset)
Definition: dataset.hpp:81
void() CacheDeallocFunc(randomx_cache *)
Definition: common.hpp:185
void initDataset(randomx_cache *cache, uint8_t *dataset, uint32_t startItem, uint32_t endItem)
Definition: dataset.cpp:192
constexpr uint64_t DatasetSize
Definition: common.hpp:86
void deallocCache(randomx_cache *cache)
Definition: dataset.cpp:61
void initDatasetItem(randomx_cache *cache, uint8_t *out, uint64_t itemNumber)
Definition: dataset.cpp:164
void() DatasetDeallocFunc(randomx_dataset *)
Definition: common.hpp:184
void initCacheCompile(randomx_cache *cache, const void *key, size_t keySize)
Definition: dataset.cpp:142
void() CacheInitializeFunc(randomx_cache *, const void *, size_t)
Definition: common.hpp:186
randomx_flags
Definition: randomx.h:42
@ RANDOMX_FLAG_ARGON2_SSSE3
Definition: randomx.h:49
@ RANDOMX_FLAG_ARGON2_AVX2
Definition: randomx.h:50
unsigned int uint32_t
Definition: stdint.h:126
unsigned char uint8_t
Definition: stdint.h:124
unsigned __int64 uint64_t
Definition: stdint.h:136
Definition: allocator.hpp:36
Definition: dataset.hpp:46
randomx_argon2_impl * argonImpl
Definition: dataset.hpp:55
randomx::SuperscalarProgram programs[RANDOMX_CACHE_ACCESSES]
Definition: dataset.hpp:52
std::vector< uint64_t > reciprocalCache
Definition: dataset.hpp:53
randomx::CacheInitializeFunc * initialize
Definition: dataset.hpp:50
uint8_t * memory
Definition: dataset.hpp:47
bool isInitialized()
Definition: dataset.hpp:57
randomx::DatasetInitFunc * datasetInit
Definition: dataset.hpp:51
randomx::CacheDeallocFunc * dealloc
Definition: dataset.hpp:48
randomx::JitCompiler * jit
Definition: dataset.hpp:49
std::string cacheKey
Definition: dataset.hpp:54
Definition: dataset.hpp:40
randomx::DatasetDeallocFunc * dealloc
Definition: dataset.hpp:42
uint8_t * memory
Definition: dataset.hpp:41
randomx_cache * cache
Definition: tests.cpp:19