Added a function to access the dataset memory buffer

Number of dataset items changed from a macro to a getter function.
This commit is contained in:
tevador 2019-04-23 22:15:55 +02:00
parent 59d82bbb01
commit b4dca14f0c
4 changed files with 31 additions and 7 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -23,7 +23,7 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
#include <stddef.h>
#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.
*

View file

@ -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);