-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5e2a99
commit 3c7c1d1
Showing
7 changed files
with
87 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <thread> | ||
#include <chrono> | ||
|
||
#include "fallback_event.h" | ||
|
||
namespace luisa::compute::fallback { | ||
|
||
void FallbackEvent::signal(uint64_t fence_value) noexcept { | ||
using A = _Atomic(uint64_t); | ||
auto p = reinterpret_cast<A *>(&_fence_value); | ||
__c11_atomic_fetch_max(p, fence_value, __ATOMIC_RELEASE); | ||
} | ||
|
||
void FallbackEvent::wait(uint64_t fence_value) const noexcept { | ||
// spin until the fence value is reached | ||
while (!is_completed(fence_value)) { | ||
using namespace std::chrono_literals; | ||
std::this_thread::sleep_for(50us); | ||
} | ||
} | ||
|
||
}// namespace luisa::compute::fallback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include <atomic> | ||
|
||
namespace luisa::compute::fallback { | ||
|
||
class FallbackEvent { | ||
|
||
private: | ||
std::atomic_uint64_t _fence_value{0u}; | ||
|
||
public: | ||
void signal(uint64_t fence_value) noexcept; | ||
void wait(uint64_t fence_value) const noexcept; | ||
[[nodiscard]] auto is_completed(uint64_t fence_value) const noexcept { return _fence_value.load(std::memory_order_acquire) >= fence_value; } | ||
[[nodiscard]] auto native_handle() noexcept { return &_fence_value; } | ||
[[nodiscard]] auto native_handle() const noexcept { return &_fence_value; } | ||
}; | ||
|
||
}// namespace luisa::compute::fallback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters