-
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
33292bb
commit 2115585
Showing
13 changed files
with
289 additions
and
57 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,75 @@ | ||
#pragma once | ||
|
||
#include <luisa/xir/instruction.h> | ||
|
||
namespace luisa::compute::xir { | ||
|
||
enum class AtomicOp { | ||
EXCHANGE, /// [(base, indices..., desired) -> old]: stores desired, returns old. | ||
COMPARE_EXCHANGE,/// [(base, indices..., expected, desired) -> old]: stores (old == expected ? desired : old), returns old. | ||
FETCH_ADD, /// [(base, indices..., val) -> old]: stores (old + val), returns old. | ||
FETCH_SUB, /// [(base, indices..., val) -> old]: stores (old - val), returns old. | ||
FETCH_AND, /// [(base, indices..., val) -> old]: stores (old & val), returns old. | ||
FETCH_OR, /// [(base, indices..., val) -> old]: stores (old | val), returns old. | ||
FETCH_XOR, /// [(base, indices..., val) -> old]: stores (old ^ val), returns old. | ||
FETCH_MIN, /// [(base, indices..., val) -> old]: stores min(old, val), returns old. | ||
FETCH_MAX, /// [(base, indices..., val) -> old]: stores max(old, val), returns old. | ||
}; | ||
|
||
[[nodiscard]] constexpr luisa::string_view to_string(AtomicOp op) noexcept { | ||
using namespace std::string_view_literals; | ||
switch (op) { | ||
case AtomicOp::EXCHANGE: return "exchange"sv; | ||
case AtomicOp::COMPARE_EXCHANGE: return "compare_exchange"sv; | ||
case AtomicOp::FETCH_ADD: return "fetch_add"sv; | ||
case AtomicOp::FETCH_SUB: return "fetch_sub"sv; | ||
case AtomicOp::FETCH_AND: return "fetch_and"sv; | ||
case AtomicOp::FETCH_OR: return "fetch_or"sv; | ||
case AtomicOp::FETCH_XOR: return "fetch_xor"sv; | ||
case AtomicOp::FETCH_MIN: return "fetch_min"sv; | ||
case AtomicOp::FETCH_MAX: return "fetch_max"sv; | ||
} | ||
return "unknown"sv; | ||
} | ||
|
||
[[nodiscard]] constexpr auto atomic_op_value_count(AtomicOp op) noexcept { | ||
return op == AtomicOp::COMPARE_EXCHANGE ? 2u : 1u; | ||
} | ||
|
||
class LC_XIR_API AtomicInst final : public DerivedInstruction<DerivedInstructionTag::ATOMIC> { | ||
|
||
private: | ||
AtomicOp _op; | ||
|
||
public: | ||
explicit AtomicInst(const Type *type = nullptr, AtomicOp op = {}, | ||
Value *base = nullptr, | ||
luisa::span<Value *const> indices = {}, | ||
luisa::span<Value *const> values = {}) noexcept; | ||
[[nodiscard]] auto op() const noexcept { return _op; } | ||
void set_op(AtomicOp op) noexcept { _op = op; } | ||
|
||
[[nodiscard]] Value *base() noexcept; | ||
[[nodiscard]] const Value *base() const noexcept; | ||
void set_base(Value *base) noexcept; | ||
|
||
[[nodiscard]] Use *base_use() noexcept; | ||
[[nodiscard]] const Use *base_use() const noexcept; | ||
|
||
[[nodiscard]] size_t index_count() const noexcept; | ||
void set_index_count(size_t count) noexcept; | ||
|
||
[[nodiscard]] luisa::span<Use *const> index_uses() noexcept; | ||
[[nodiscard]] luisa::span<const Use *const> index_uses() const noexcept; | ||
void set_indices(luisa::span<Value *const> indices) noexcept; | ||
|
||
[[nodiscard]] size_t value_count() const noexcept { | ||
return atomic_op_value_count(_op); | ||
} | ||
|
||
[[nodiscard]] luisa::span<Use *const> value_uses() noexcept; | ||
[[nodiscard]] luisa::span<const Use *const> value_uses() const noexcept; | ||
void set_values(luisa::span<Value *const> values) noexcept; | ||
}; | ||
|
||
}// namespace luisa::compute::xir |
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
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
Oops, something went wrong.