Skip to content

Commit b4dca14

Browse files
committed
Added a function to access the dataset memory buffer
Number of dataset items changed from a macro to a getter function.
1 parent 59d82bb commit b4dca14

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

src/common.hpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,11 @@ namespace randomx {
5454

5555
constexpr int ArgonBlockSize = 1024;
5656
constexpr int ArgonSaltSize = sizeof(RANDOMX_ARGON_SALT) - 1;
57-
constexpr int CacheLineSize = 64;
57+
constexpr int CacheLineSize = RANDOMX_DATASET_ITEM_SIZE;
5858
constexpr int ScratchpadSize = RANDOMX_SCRATCHPAD_L3;
5959
constexpr uint32_t CacheLineAlignMask = (RANDOMX_DATASET_SIZE - 1) & ~(CacheLineSize - 1);
6060
constexpr uint32_t CacheSize = RANDOMX_ARGON_MEMORY * 1024;
6161

62-
static_assert(RANDOMX_DATASET_ITEMS == RANDOMX_DATASET_SIZE / CacheLineSize, "Invalid value of RANDOMX_DATASET_ITEMS");
63-
6462
#ifdef TRACE
6563
constexpr bool trace = true;
6664
#else

src/randomx.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,19 @@ extern "C" {
9090
return dataset;
9191
}
9292

93+
unsigned long randomx_dataset_item_count() {
94+
return RANDOMX_DATASET_SIZE / RANDOMX_DATASET_ITEM_SIZE;
95+
}
96+
9397
void randomx_init_dataset(randomx_dataset *dataset, randomx_cache *cache, unsigned long startItem, unsigned long itemCount) {
9498
randomx::DatasetInitFunc dsfunc = cache->getInitFunc();
9599
dsfunc(cache, dataset->memory + startItem * randomx::CacheLineSize, startItem, startItem + itemCount);
96100
}
97101

102+
void *randomx_get_dataset_memory(randomx_dataset *dataset) {
103+
return dataset->memory;
104+
}
105+
98106
void randomx_release_dataset(randomx_dataset *dataset) {
99107
delete dataset;
100108
}

src/randomx.h

+19-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
2323
#include <stddef.h>
2424

2525
#define RANDOMX_HASH_SIZE 32
26-
#define RANDOMX_DATASET_ITEMS 33554432UL
26+
#define RANDOMX_DATASET_ITEM_SIZE 64
2727

2828
typedef enum {
2929
RANDOMX_FLAG_DEFAULT = 0,
@@ -82,10 +82,17 @@ void randomx_release_cache(randomx_cache* cache);
8282
*/
8383
randomx_dataset *randomx_alloc_dataset(randomx_flags flags);
8484

85+
/**
86+
* Gets the number of items contained in the dataset.
87+
*
88+
* @return the number of items contained in the dataset.
89+
*/
90+
unsigned long randomx_dataset_item_count();
91+
8592
/**
8693
* Initializes dataset items.
8794
*
88-
* Note: In order to use the Dataset, all items from 0 to (RANDOMX_DATASET_ITEMS - 1) must be initialized.
95+
* Note: In order to use the Dataset, all items from 0 to (randomx_dataset_item_count() - 1) must be initialized.
8996
* This may be done by several calls to this function using non-overlapping item sequences.
9097
*
9198
* @param dataset is a pointer to a previously allocated randomx_dataset structure. Must not be NULL.
@@ -95,6 +102,16 @@ randomx_dataset *randomx_alloc_dataset(randomx_flags flags);
95102
*/
96103
void randomx_init_dataset(randomx_dataset *dataset, randomx_cache *cache, unsigned long startItem, unsigned long itemCount);
97104

105+
/**
106+
* Returns a pointer to the internal memory buffer of the dataset structure. The size
107+
* of the internal memory buffer is randomx_dataset_item_count() * RANDOMX_DATASET_ITEM_SIZE.
108+
*
109+
* @param dataset is dataset is a pointer to a previously allocated randomx_dataset structure. Must not be NULL.
110+
*
111+
* @return Pointer to the internal memory buffer of the dataset structure.
112+
*/
113+
void *randomx_get_dataset_memory(randomx_dataset *dataset);
114+
98115
/**
99116
* Releases all memory occupied by the randomx_dataset structure.
100117
*

src/tests/api-example2.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ int main() {
2020
std::cout << "Dataset allocation failed" << std::endl;
2121
return 1;
2222
}
23-
std::thread t1(&randomx_init_dataset, myDataset, myCache, 0, RANDOMX_DATASET_ITEMS / 2);
24-
std::thread t2(&randomx_init_dataset, myDataset, myCache, RANDOMX_DATASET_ITEMS / 2, RANDOMX_DATASET_ITEMS / 2);
23+
auto datasetItemCount = randomx_dataset_item_count();
24+
std::thread t1(&randomx_init_dataset, myDataset, myCache, 0, datasetItemCount / 2);
25+
std::thread t2(&randomx_init_dataset, myDataset, myCache, datasetItemCount / 2, datasetItemCount / 2);
2526
t1.join();
2627
t2.join();
2728
randomx_release_cache(myCache);

0 commit comments

Comments
 (0)