@@ -81,12 +81,14 @@ bool CUDAMiner::initEpoch_internal()
81
81
bool retVar = false ;
82
82
m_current_target = 0 ;
83
83
auto startInit = std::chrono::steady_clock::now ();
84
- size_t RequiredMemory = (m_epochContext.dagSize + m_epochContext.lightSize );
84
+ size_t RequiredTotalMemory = (m_epochContext.dagSize + m_epochContext.lightSize );
85
+ size_t RequiredDagMemory = m_epochContext.dagSize ;
85
86
86
87
// Release the pause flag if any
87
88
resume (MinerPauseEnum::PauseDueToInsufficientMemory);
88
89
resume (MinerPauseEnum::PauseDueToInitEpochError);
89
90
91
+ bool lightOnHost = false ;
90
92
try
91
93
{
92
94
hash128_t * dag;
@@ -104,21 +106,34 @@ bool CUDAMiner::initEpoch_internal()
104
106
CUDA_SAFE_CALL (cudaDeviceSetCacheConfig (cudaFuncCachePreferL1));
105
107
106
108
// Check whether the current device has sufficient memory every time we recreate the dag
107
- if (m_deviceDescriptor.totalMemory < RequiredMemory )
109
+ if (m_deviceDescriptor.totalMemory < RequiredTotalMemory )
108
110
{
109
- cudalog << " Epoch " << m_epochContext.epochNumber << " requires "
110
- << dev::getFormattedMemory ((double )RequiredMemory) << " memory." ;
111
- cudalog << " This device hasn't available. Mining suspended ..." ;
112
- pause (MinerPauseEnum::PauseDueToInsufficientMemory);
113
- return true ; // This will prevent to exit the thread and
114
- // Eventually resume mining when changing coin or epoch (NiceHash)
111
+ if (m_deviceDescriptor.totalMemory < RequiredDagMemory)
112
+ {
113
+ cudalog << " Epoch " << m_epochContext.epochNumber << " requires "
114
+ << dev::getFormattedMemory ((double )RequiredDagMemory) << " memory." ;
115
+ cudalog << " This device hasn't enough memory available. Mining suspended ..." ;
116
+ pause (MinerPauseEnum::PauseDueToInsufficientMemory);
117
+ return true ; // This will prevent to exit the thread and
118
+ // Eventually resume mining when changing coin or epoch (NiceHash)
119
+ }
120
+ else
121
+ lightOnHost = true ;
115
122
}
116
123
117
- cudalog << " Generating DAG + Light : "
118
- << dev::getFormattedMemory ((double )RequiredMemory );
124
+ cudalog << " Generating DAG + Light(on " << (lightOnHost ? " host " : " GPU " )
125
+ << " ) : " << dev::getFormattedMemory ((double )RequiredTotalMemory );
119
126
120
127
// create buffer for cache
121
- CUDA_SAFE_CALL (cudaMalloc (reinterpret_cast <void **>(&light), m_epochContext.lightSize ));
128
+ if (lightOnHost)
129
+ {
130
+ CUDA_SAFE_CALL (cudaHostAlloc (reinterpret_cast <void **>(&light),
131
+ m_epochContext.lightSize , cudaHostAllocDefault));
132
+ cudalog << " WARNING: Generating DAG will take minutes, not seconds" ;
133
+ }
134
+ else
135
+ CUDA_SAFE_CALL (
136
+ cudaMalloc (reinterpret_cast <void **>(&light), m_epochContext.lightSize ));
122
137
m_allocated_memory_light_cache = m_epochContext.lightSize ;
123
138
CUDA_SAFE_CALL (cudaMalloc (reinterpret_cast <void **>(&dag), m_epochContext.dagSize ));
124
139
m_allocated_memory_dag = m_epochContext.dagSize ;
@@ -133,7 +148,7 @@ bool CUDAMiner::initEpoch_internal()
133
148
else
134
149
{
135
150
cudalog << " Generating DAG + Light (reusing buffers): "
136
- << dev::getFormattedMemory ((double )RequiredMemory );
151
+ << dev::getFormattedMemory ((double )RequiredTotalMemory );
137
152
get_constants (&dag, NULL , &light, NULL );
138
153
}
139
154
@@ -151,7 +166,9 @@ bool CUDAMiner::initEpoch_internal()
151
166
std::chrono::steady_clock::now () - startInit)
152
167
.count ()
153
168
<< " ms. "
154
- << dev::getFormattedMemory ((double )(m_deviceDescriptor.totalMemory - RequiredMemory))
169
+ << dev::getFormattedMemory (
170
+ lightOnHost ? (double )(m_deviceDescriptor.totalMemory - RequiredDagMemory) :
171
+ (double )(m_deviceDescriptor.totalMemory - RequiredTotalMemory))
155
172
<< " left." ;
156
173
157
174
retVar = true ;
@@ -271,7 +288,9 @@ void CUDAMiner::enumDevices(std::map<string, DeviceDescriptor>& _DevicesCollecti
271
288
272
289
try
273
290
{
291
+ size_t freeMem, totalMem;
274
292
CUDA_SAFE_CALL (cudaGetDeviceProperties (&props, i));
293
+ CUDA_SAFE_CALL (cudaMemGetInfo (&freeMem, &totalMem));
275
294
s << setw (2 ) << setfill (' 0' ) << hex << props.pciBusID << " :" << setw (2 )
276
295
<< props.pciDeviceID << " .0" ;
277
296
uniqueId = s.str ();
@@ -288,7 +307,7 @@ void CUDAMiner::enumDevices(std::map<string, DeviceDescriptor>& _DevicesCollecti
288
307
deviceDescriptor.cuDeviceIndex = i;
289
308
deviceDescriptor.cuDeviceOrdinal = i;
290
309
deviceDescriptor.cuName = string (props.name );
291
- deviceDescriptor.totalMemory = props. totalGlobalMem ;
310
+ deviceDescriptor.totalMemory = freeMem ;
292
311
deviceDescriptor.cuCompute =
293
312
(to_string (props.major ) + " ." + to_string (props.minor ));
294
313
deviceDescriptor.cuComputeMajor = props.major ;
0 commit comments