Do not allocate dataset in light mode

This commit is contained in:
DataHoarder 2023-05-14 10:12:26 +02:00
parent f42f23de84
commit 2981fc46ad
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
3 changed files with 44 additions and 10 deletions

View file

@ -128,6 +128,11 @@ func AllocDataset(flags ...Flag) (*C.randomx_dataset, error) {
}
var dataset *C.randomx_dataset
//do not allocate
if (SumFlag & FlagFullMEM) == 0 {
return dataset, nil
}
dataset = C.randomx_alloc_dataset(SumFlag.toC())
if dataset == nil {
return nil, errors.New("failed to alloc mem for dataset")
@ -188,10 +193,6 @@ func CreateVM(cache *C.randomx_cache, dataset *C.randomx_dataset, flags ...Flag)
SumFlag = SumFlag | flag
}
if dataset == nil {
panic("failed creating vm: using empty dataset")
}
vm := C.randomx_create_vm(SumFlag.toC(), cache, dataset)
if vm == nil {

View file

@ -44,8 +44,8 @@ func TestAllocCache(t *testing.T) {
}
func TestAllocDataset(t *testing.T) {
ds, _ := AllocDataset(Flag(GetFlags()))
cache, _ := AllocCache(Flag(GetFlags()))
ds, _ := AllocDataset(Flag(GetFlags()), FlagFullMEM)
cache, _ := AllocCache(Flag(GetFlags()), FlagFullMEM)
seed := make([]byte, 32)
InitCache(cache, seed)
@ -69,7 +69,7 @@ func TestCreateVM(t *testing.T) {
InitCache(cache, seed)
log.Println("cache initialization finished")
ds, _ := AllocDataset(Flag(GetFlags()))
ds, _ := AllocDataset(Flag(GetFlags()), FlagFullMEM)
log.Println("alloc dataset mem finished")
count := DatasetItemCount()
log.Println("dataset count:", count)
@ -86,7 +86,34 @@ func TestCreateVM(t *testing.T) {
}
wg.Wait()
log.Println("dataset initialization finished") // too slow when one thread
vm, _ := CreateVM(cache, ds, Flag(GetFlags()))
vm, _ := CreateVM(cache, ds, Flag(GetFlags()), FlagFullMEM)
var hashCorrect = make([]byte, hex.DecodedLen(len(tp[2])))
_, err := hex.Decode(hashCorrect, tp[2])
if err != nil {
log.Println(err)
}
hash := CalculateHash(vm, tp[1])
if bytes.Compare(hash, hashCorrect) != 0 {
t.Log(hex.EncodeToString(hash))
t.Log(hex.EncodeToString(hashCorrect))
t.Fail()
}
}
func TestCreateVMLight(t *testing.T) {
runtime.GOMAXPROCS(runtime.NumCPU())
var tp = testPairs[pairToTest]
cache, _ := AllocCache(Flag(GetFlags()))
log.Println("alloc cache mem finished")
seed := tp[0]
InitCache(cache, seed)
log.Println("cache initialization finished")
log.Println("dataset initialization finished") // too slow when one thread
vm, _ := CreateVM(cache, nil, Flag(GetFlags()))
var hashCorrect = make([]byte, hex.DecodedLen(len(tp[2])))
_, err := hex.Decode(hashCorrect, tp[2])
@ -110,14 +137,14 @@ func TestNewRxVM(t *testing.T) {
workerNum := uint32(runtime.NumCPU())
seed := pair[0]
dataset, _ := NewRxDataset(FlagJIT)
dataset, _ := NewRxDataset(FlagJIT, FlagFullMEM)
if dataset.GoInit(seed, workerNum) == false {
log.Fatal("failed to init dataset")
}
//defer dataset.Close()
fmt.Println("Finished generating dataset in", time.Since(start).Seconds(), "sec")
vm, _ := NewRxVM(dataset, Flag(GetFlags()))
vm, _ := NewRxVM(dataset, Flag(GetFlags()), FlagFullMEM)
//defer vm.Close()
blob := pair[1]

View file

@ -34,6 +34,9 @@ func (ds *RxDataset) Close() {
}
func (ds *RxDataset) GoInit(seed []byte, workerNum uint32) bool {
if ds.dataset == nil {
return true
}
if ds.rxCache.Init(seed) == false {
fmt.Println("WARN: rxCache has already been initialized by the same seed")
}
@ -60,6 +63,9 @@ func (ds *RxDataset) GoInit(seed []byte, workerNum uint32) bool {
}
func (ds *RxDataset) CInit(seed []byte, workerNum uint32) bool {
if ds.dataset == nil {
return true
}
if ds.rxCache.Init(seed) == false {
fmt.Println("WARN: rxCache has already been initialized by the same seed")
}