Monero
dataset.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2018-2019, tevador <tevador@gmail.com>
3 
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, 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 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF 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"
35 #include "superscalar_program.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 */
46 struct randomx_cache {
47  uint8_t* memory = nullptr;
53  std::vector<uint64_t> reciprocalCache;
56 
57  bool isInitialized() {
58  return programs[0].getSize() != 0;
59  }
60 };
61 
62 //A pointer to a standard-layout struct object points to its initial member
63 static_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
73 static_assert(std::is_standard_layout<randomx_cache>(), "randomx_cache must be a standard-layout struct");
74 #endif
75 
76 namespace 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 
96  return randomx_argon2_impl_avx2();
97  }
100  }
102  }
103 }
Definition: dataset.hpp:46
randomx::CacheInitializeFunc * initialize
Definition: dataset.hpp:50
void() DatasetDeallocFunc(randomx_dataset *)
Definition: common.hpp:191
Definition: allocator.cpp:35
#define RANDOMX_CACHE_ACCESSES
Definition: configuration.h:44
void() DatasetInitFunc(randomx_cache *cache, uint8_t *dataset, uint32_t startBlock, uint32_t endBlock)
Definition: common.hpp:189
void deallocDataset(randomx_dataset *dataset)
Definition: dataset.hpp:81
Definition: randomx.h:50
Definition: dataset.hpp:40
void deallocCache(randomx_cache *cache)
Definition: dataset.cpp:61
Definition: jit_compiler_fallback.hpp:42
::std::string string
Definition: gtest-port.h:1097
Definition: superscalar_program.hpp:37
randomx::DatasetInitFunc * datasetInit
Definition: dataset.hpp:51
randomx::JitCompiler * jit
Definition: dataset.hpp:49
uint8_t * memory
Definition: dataset.hpp:47
unsigned char uint8_t
Definition: stdint.h:124
void initCacheCompile(randomx_cache *cache, const void *key, size_t keySize)
Definition: dataset.cpp:142
randomx_argon2_impl * randomx_argon2_impl_ssse3()
Definition: argon2_ssse3.c:48
static int flags
Definition: mdb_load.c:31
void randomx_argon2_impl(const argon2_instance_t *instance, argon2_position_t position)
Definition: argon2.h:238
Definition: randomx.h:49
Definition: allocator.hpp:36
bool isInitialized()
Definition: dataset.hpp:57
unsigned int uint32_t
Definition: stdint.h:126
uint8_t * memory
Definition: dataset.hpp:41
randomx_argon2_impl * randomx_argon2_impl_avx2()
Definition: argon2_avx2.c:44
randomx_flags
Definition: randomx.h:42
unsigned __int64 uint64_t
Definition: stdint.h:136
void initDatasetItem(randomx_cache *cache, uint8_t *out, uint64_t itemNumber)
Definition: dataset.cpp:164
std::string cacheKey
Definition: dataset.hpp:54
void() CacheInitializeFunc(randomx_cache *, const void *, size_t)
Definition: common.hpp:193
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
randomx_cache * cache
Definition: tests.cpp:19
randomx::SuperscalarProgram programs[RANDOMX_CACHE_ACCESSES]
Definition: dataset.hpp:52
randomx_argon2_impl * selectArgonImpl(randomx_flags flags)
Definition: dataset.hpp:94
void randomx_argon2_fill_segment_ref(const argon2_instance_t *instance, argon2_position_t position)
Definition: argon2_ref.c:110
void initCache(randomx_cache *cache, const void *key, size_t keySize)
Definition: dataset.cpp:71
randomx::DatasetDeallocFunc * dealloc
Definition: dataset.hpp:42
randomx::CacheDeallocFunc * dealloc
Definition: dataset.hpp:48
randomx_argon2_impl * argonImpl
Definition: dataset.hpp:55
void() CacheDeallocFunc(randomx_cache *)
Definition: common.hpp:192
std::vector< uint64_t > reciprocalCache
Definition: dataset.hpp:53
uint32_t getSize()
Definition: superscalar_program.hpp:46