Skip to content

Commit 26374ab

Browse files
committed
WIP
1 parent 2ceeb08 commit 26374ab

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

src/include/utils_internal.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class TokenPool : public std::enable_shared_from_this<TokenPool> {
7474
uint64_t* baseAddr_;
7575
uint64_t tailMask_;
7676
std::shared_ptr<uint64_t> tokens_;
77-
std::vector<uint64_t> allocationMap_;
77+
std::vector<std::bitset<UINT64_WIDTH>> allocationMap_;
7878
};
7979

8080
} // namespace mscclpp

src/semaphore.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ struct SemaphoreStub::Impl {
2929
};
3030

3131
std::shared_ptr<uint64_t> SemaphoreStub::Impl::gpuCallocToken(std::shared_ptr<Context> context) {
32-
// NVLS is not supported in ROCm/HIP
3332
#if (CUDA_NVLS_API_AVAILABLE)
3433
if (isNvlsSupported()) {
3534
return context->pimpl_->getToken();

src/utils_internal.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,22 +251,22 @@ std::shared_ptr<uint64_t> TokenPool::getToken() {
251251
size_t index = (token - self->baseAddr_) / UINT64_WIDTH;
252252
size_t bit = (token - self->baseAddr_) % UINT64_WIDTH;
253253
uint64_t mask = 1UL << bit;
254-
if ((self->allocationMap_[index] & mask) == 0) {
255-
WARN("TokenPool tried to free a token that was not allocated");
256-
return;
257-
}
258254
self->allocationMap_[index] &= ~mask;
259255
};
260256

261257
size_t size = allocationMap_.size();
262258
for (size_t i = 0; i < size; i++) {
259+
uint64_t ullong = allocationMap_[i].to_ullong();
263260
uint64_t mask = (i + 1 == size) ? tailMask_ : ~0ULL;
264-
uint64_t holes = (~allocationMap_[i]) & mask;
261+
uint64_t holes = (~ullong) & mask;
265262
if (!holes) continue;
266-
size_t bit = __builtin_ctzll(holes);
267-
allocationMap_[i] |= (1UL << bit);
268-
INFO(MSCCLPP_ALLOC, "TokenPool allocated token at addr %p", baseAddr_ + i * UINT64_WIDTH + bit);
269-
return std::shared_ptr<uint64_t>(baseAddr_ + i * UINT64_WIDTH + bit, deleter);
263+
for (int bit = 0; bit < UINT64_WIDTH; bit++) {
264+
if (holes & (1UL << bit)) {
265+
allocationMap_[i].set(bit);
266+
INFO(MSCCLPP_ALLOC, "TokenPool allocated token at addr %p", baseAddr_ + i * UINT64_WIDTH + bit);
267+
return std::shared_ptr<uint64_t>(baseAddr_ + i * UINT64_WIDTH + bit, deleter);
268+
}
269+
}
270270
}
271271
throw Error("TokenPool is exhausted", ErrorCode::InternalError);
272272
}

0 commit comments

Comments
 (0)