diff --git a/src/common.hpp b/src/common.hpp
index d5f5e31..a35f8ec 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -54,13 +54,11 @@ namespace randomx {
constexpr int ArgonBlockSize = 1024;
constexpr int ArgonSaltSize = sizeof(RANDOMX_ARGON_SALT) - 1;
- constexpr int CacheLineSize = 64;
+ constexpr int CacheLineSize = RANDOMX_DATASET_ITEM_SIZE;
constexpr int ScratchpadSize = RANDOMX_SCRATCHPAD_L3;
constexpr uint32_t CacheLineAlignMask = (RANDOMX_DATASET_SIZE - 1) & ~(CacheLineSize - 1);
constexpr uint32_t CacheSize = RANDOMX_ARGON_MEMORY * 1024;
- static_assert(RANDOMX_DATASET_ITEMS == RANDOMX_DATASET_SIZE / CacheLineSize, "Invalid value of RANDOMX_DATASET_ITEMS");
-
#ifdef TRACE
constexpr bool trace = true;
#else
diff --git a/src/randomx.cpp b/src/randomx.cpp
index 2dcf03f..c75afcd 100644
--- a/src/randomx.cpp
+++ b/src/randomx.cpp
@@ -90,11 +90,19 @@ extern "C" {
return dataset;
}
+ unsigned long randomx_dataset_item_count() {
+ return RANDOMX_DATASET_SIZE / RANDOMX_DATASET_ITEM_SIZE;
+ }
+
void randomx_init_dataset(randomx_dataset *dataset, randomx_cache *cache, unsigned long startItem, unsigned long itemCount) {
randomx::DatasetInitFunc dsfunc = cache->getInitFunc();
dsfunc(cache, dataset->memory + startItem * randomx::CacheLineSize, startItem, startItem + itemCount);
}
+ void *randomx_get_dataset_memory(randomx_dataset *dataset) {
+ return dataset->memory;
+ }
+
void randomx_release_dataset(randomx_dataset *dataset) {
delete dataset;
}
diff --git a/src/randomx.h b/src/randomx.h
index f333e22..590c48f 100644
--- a/src/randomx.h
+++ b/src/randomx.h
@@ -23,7 +23,7 @@ along with RandomX. If not, see.
#include
#define RANDOMX_HASH_SIZE 32
-#define RANDOMX_DATASET_ITEMS 33554432UL
+#define RANDOMX_DATASET_ITEM_SIZE 64
typedef enum {
RANDOMX_FLAG_DEFAULT = 0,
@@ -82,10 +82,17 @@ void randomx_release_cache(randomx_cache* cache);
*/
randomx_dataset *randomx_alloc_dataset(randomx_flags flags);
+/**
+ * Gets the number of items contained in the dataset.
+ *
+ * @return the number of items contained in the dataset.
+*/
+unsigned long randomx_dataset_item_count();
+
/**
* Initializes dataset items.
*
- * Note: In order to use the Dataset, all items from 0 to (RANDOMX_DATASET_ITEMS - 1) must be initialized.
+ * Note: In order to use the Dataset, all items from 0 to (randomx_dataset_item_count() - 1) must be initialized.
* This may be done by several calls to this function using non-overlapping item sequences.
*
* @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);
*/
void randomx_init_dataset(randomx_dataset *dataset, randomx_cache *cache, unsigned long startItem, unsigned long itemCount);
+/**
+ * Returns a pointer to the internal memory buffer of the dataset structure. The size
+ * of the internal memory buffer is randomx_dataset_item_count() * RANDOMX_DATASET_ITEM_SIZE.
+ *
+ * @param dataset is dataset is a pointer to a previously allocated randomx_dataset structure. Must not be NULL.
+ *
+ * @return Pointer to the internal memory buffer of the dataset structure.
+*/
+void *randomx_get_dataset_memory(randomx_dataset *dataset);
+
/**
* Releases all memory occupied by the randomx_dataset structure.
*
diff --git a/src/tests/api-example2.cpp b/src/tests/api-example2.cpp
index 1ad6420..216160a 100644
--- a/src/tests/api-example2.cpp
+++ b/src/tests/api-example2.cpp
@@ -20,8 +20,9 @@ int main() {
std::cout << "Dataset allocation failed" << std::endl;
return 1;
}
- std::thread t1(&randomx_init_dataset, myDataset, myCache, 0, RANDOMX_DATASET_ITEMS / 2);
- std::thread t2(&randomx_init_dataset, myDataset, myCache, RANDOMX_DATASET_ITEMS / 2, RANDOMX_DATASET_ITEMS / 2);
+ auto datasetItemCount = randomx_dataset_item_count();
+ std::thread t1(&randomx_init_dataset, myDataset, myCache, 0, datasetItemCount / 2);
+ std::thread t2(&randomx_init_dataset, myDataset, myCache, datasetItemCount / 2, datasetItemCount / 2);
t1.join();
t2.join();
randomx_release_cache(myCache);