Skip to content

Commit 1759ca5

Browse files
committed
fix some errors
1 parent f22b5f5 commit 1759ca5

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

Diff for: ggml/src/ggml-cann/ggml-cann.cpp

+21-22
Original file line numberDiff line numberDiff line change
@@ -160,54 +160,53 @@ struct ggml_cann_pool_buf_prio : public ggml_cann_pool {
160160
* @brief The maximum reuse margin for a buffer.
161161
*/
162162
static const size_t max_reuse_margin = 1ull << 22; // 4MB
163-
163+
164164
/**
165165
* @brief The minimum free margin for a buffer.
166166
*/
167167
static const size_t min_free_margin = 1ull << 20; // 1MB
168-
169-
168+
170169
/**
171170
* @brief The alignment for buffer allocation.
172171
*/
173-
static const size_t alignment = 128;
174-
172+
static const size_t alignment = 128;
173+
175174
/**
176175
* @brief The device ID associated with this buffer pool.
177176
*/
178177
int device;
179-
178+
180179
/**
181180
* @brief Whether to disable clean during buffer allocation.
182181
*/
183182
bool disable_clean = false;
184-
183+
185184
/**
186185
* @brief Structure representing a CANN buffer.
187186
*/
188187
struct ggml_cann_buffer {
189188
void* ptr = nullptr; ///< Pointer to the buffer.
190189
size_t size = 0; ///< Size of the buffer.
191190
std::chrono::steady_clock::time_point last_used; ///< Last used time.
192-
191+
193192
bool operator>(const ggml_cann_buffer& other) const {
194193
return size > other.size;
195194
}
196195
};
197-
196+
198197
/**
199198
* @brief Array of CANN buffers in the pool.
200199
*/
201200
std::unordered_map<void*, size_t> buffer_pool;
202201
std::priority_queue<ggml_cann_buffer,
203202
std::vector<ggml_cann_buffer>,
204203
std::greater<>> free_buffers ;
205-
204+
206205
/**
207206
* @brief Total size of all buffers in the pool.
208207
*/
209208
size_t pool_size = 0;
210-
209+
211210
/**
212211
* @brief Constructor to initialize the buffer pool for a specific device.
213212
*
@@ -216,7 +215,7 @@ struct ggml_cann_pool_buf_prio : public ggml_cann_pool {
216215
explicit ggml_cann_pool_buf_prio(int device) : device(device) {
217216
disable_clean = getenv("GGML_CANN_DISABLE_BUF_POOL_CLEAN") != nullptr;
218217
}
219-
218+
220219
/**
221220
* @brief Destructor to free all buffers in the pool.
222221
*/
@@ -229,7 +228,7 @@ struct ggml_cann_pool_buf_prio : public ggml_cann_pool {
229228
buffer_pool.clear();
230229
GGML_ASSERT(pool_size == 0);
231230
}
232-
231+
233232
/**
234233
* @brief Allocate a buffer of the given size.
235234
*
@@ -243,16 +242,16 @@ struct ggml_cann_pool_buf_prio : public ggml_cann_pool {
243242
if (size == 0) {
244243
size = alignment;
245244
}
246-
245+
247246
void* ptr = nullptr;
248247
auto now = std::chrono::steady_clock::now();
249-
248+
250249
std::vector<ggml_cann_buffer> free_buffers_rest;
251250
free_buffers_rest.reserve(free_buffers.size());
252251
while (!free_buffers.empty()) {
253252
auto b = free_buffers.top();
254253
free_buffers.pop();
255-
254+
256255
if (b.size >= size) {
257256
// reuse the buffer if the size is enough
258257
const size_t margin = b.size - size;
@@ -273,7 +272,7 @@ struct ggml_cann_pool_buf_prio : public ggml_cann_pool {
273272
break;
274273
}
275274
}
276-
275+
277276
bool should_clean = !disable_clean &&
278277
b.size > min_free_margin &&
279278
std::chrono::duration_cast<std::chrono::milliseconds>(now - b.last_used).count() > 100;
@@ -298,14 +297,14 @@ struct ggml_cann_pool_buf_prio : public ggml_cann_pool {
298297
for (ggml_cann_buffer &b : free_buffers_rest) {
299298
free_buffers.push(std::move(b));
300299
}
301-
300+
302301
#ifdef DEBUG_CANN_MALLOC
303302
GGML_LOG_INFO("cann pool[%d] free pool_size = %5u MB\n\n", device, (uint32_t)(GGML_PAD(pool_size, 1048576) / 1048576));
304303
#endif
305304
if (ptr != nullptr) {
306305
return ptr;
307306
}
308-
307+
309308
// allocate a new buffer if no buffer can be reused
310309
ggml_cann_set_device(device);
311310
ACL_CHECK(aclrtMalloc(&ptr, size, ACL_MEM_MALLOC_HUGE_FIRST));
@@ -322,7 +321,7 @@ struct ggml_cann_pool_buf_prio : public ggml_cann_pool {
322321
buffer_pool.emplace(ptr, size);
323322
return ptr;
324323
}
325-
324+
326325
/**
327326
* @brief Free a buffer and return it to the pool.
328327
*
@@ -334,7 +333,7 @@ struct ggml_cann_pool_buf_prio : public ggml_cann_pool {
334333
if (it == buffer_pool.end()) {
335334
GGML_ABORT("cann pool[%d]: buffer %p not found in pool\n", device, ptr);
336335
}
337-
336+
338337
auto now = std::chrono::steady_clock::now();
339338
free_buffers.emplace(ggml_cann_buffer{ptr, it->second, now});
340339
#ifdef DEBUG_CANN_MALLOC
@@ -346,7 +345,7 @@ struct ggml_cann_pool_buf_prio : public ggml_cann_pool {
346345
#endif
347346
}
348347
};
349-
348+
350349
/**
351350
* @brief A pool of CANN buffers(segment buffer).
352351
*

0 commit comments

Comments
 (0)