Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev-fallback-backend' into dev-xir
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxwellGengYF committed Dec 17, 2024
2 parents 2ef8938 + f5e2a99 commit 1c73a3b
Show file tree
Hide file tree
Showing 112 changed files with 17,576 additions and 11,706 deletions.
8 changes: 4 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
url = https://github.com/LuisaGroup/reproc.git
[submodule "src/ext/marl"]
path = src/ext/marl
url = https://github.com/LuisaGroup/marl.git
[submodule "src/ext/yyjson"]
path = src/ext/yyjson
url = https://github.com/ibireme/yyjson.git
url = https://github.com/LuisaGroup/marl.git
[submodule "src/ext/yyjson"]
path = src/ext/yyjson
url = https://github.com/ibireme/yyjson.git
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ if (NOT SKBUILD AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/options.cmake")
else ()
option(LUISA_COMPUTE_ENABLE_DSL "Enable C++ DSL" ON)
option(LUISA_COMPUTE_ENABLE_TENSOR "Enable C++ DSL tensor extension" ON)
option(LUISA_COMPUTE_ENABLE_DX "Enable DirectX backend" OFF)
option(LUISA_COMPUTE_ENABLE_METAL "Enable Metal backend" OFF)
option(LUISA_COMPUTE_ENABLE_DX "Enable DirectX backend" ON)
option(LUISA_COMPUTE_ENABLE_METAL "Enable Metal backend" ON)
option(LUISA_COMPUTE_ENABLE_CUDA "Enable CUDA backend" ON)
option(LUISA_COMPUTE_ENABLE_CUDA_EXT_LCUB "Enable CUDA extension: LCUB" OFF)
option(LUISA_COMPUTE_ENABLE_VULKAN "Enable Vulkan backend" OFF)
option(LUISA_COMPUTE_ENABLE_CPU "Enable CPU backend" OFF)
option(LUISA_COMPUTE_ENABLE_CPU "Enable CPU backend" ON)
option(LUISA_COMPUTE_ENABLE_FALLBACK "Enable Fallback backend" ON)
option(LUISA_COMPUTE_ENABLE_REMOTE "Enable Remote backend" ON)
option(LUISA_COMPUTE_ENABLE_GUI "Enable GUI support" ON)
Expand Down
5 changes: 4 additions & 1 deletion include/luisa/ast/op.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,12 @@ enum struct CallOp : uint32_t {

// SER
SHADER_EXECUTION_REORDER,// (uint hint, uint hint_bits): void

// Clock
CLOCK, // (): uint64
};

static constexpr size_t call_op_count = to_underlying(CallOp::SHADER_EXECUTION_REORDER) + 1u;
static constexpr size_t call_op_count = to_underlying(CallOp::CLOCK) + 1u;

[[nodiscard]] constexpr auto is_atomic_operation(CallOp op) noexcept {
auto op_value = luisa::to_underlying(op);
Expand Down
98 changes: 44 additions & 54 deletions include/luisa/core/intrin.h
Original file line number Diff line number Diff line change
@@ -1,54 +1,44 @@
#pragma once

#if defined(__x86_64__) || defined(_M_X64)
#define LUISA_ARCH_X86_64
#elif defined(__aarch64__)
#define LUISA_ARCH_ARM64
#else
#error Unsupported architecture
#endif

#if defined(LUISA_ARCH_X86_64)

#include <immintrin.h>
#include <cstdint>
#include <cassert>

#define LUISA_INTRIN_PAUSE() _mm_pause()

namespace luisa {
using float16_t = int16_t;
using float32x4_t = __m128;
}// namespace luisa

#elif defined(LUISA_ARCH_ARM64)

#include <arm_neon.h>

namespace luisa {
using float16_t = ::float16_t;
using float32x4_t = ::float32x4_t;
}// namespace luisa

#define LUISA_INTRIN_PAUSE() asm volatile("isb")

#else

#include <thread>
#define LUISA_INTRIN_PAUSE() std::this_thread::yield()

#endif

////////////// assume
#ifdef NDEBUG // assume only enabled in non-debug mode.
#if defined(__clang__)// Clang
#define LUISA_ASSUME(x) (__builtin_assume(x))
#elif defined(_MSC_VER)// MSVC
#define LUISA_ASSUME(x) (__assume(x))
#else// GCC
#define LUISA_ASSUME(x) \
if (!(x)) __builtin_unreachable()
#endif
#else
#define LUISA_ASSUME(expression) assert(expression)
#endif
#pragma once

#if defined(__x86_64__) || defined(_M_X64)
#define LUISA_ARCH_X86_64
#elif defined(__aarch64__)
#define LUISA_ARCH_ARM64
#else
#error Unsupported architecture
#endif

#if defined(LUISA_ARCH_X86_64)

#include <immintrin.h>
#include <cstdint>
#include <cassert>

#define LUISA_INTRIN_PAUSE() _mm_pause()

#elif defined(LUISA_ARCH_ARM64)

#include <arm_neon.h>

#define LUISA_INTRIN_PAUSE() asm volatile("isb")

#else

#include <thread>
#define LUISA_INTRIN_PAUSE() std::this_thread::yield()

#endif

////////////// assume
#ifdef NDEBUG // assume only enabled in non-debug mode.
#if defined(__clang__)// Clang
#define LUISA_ASSUME(x) (__builtin_assume(x))
#elif defined(_MSC_VER)// MSVC
#define LUISA_ASSUME(x) (__assume(x))
#else// GCC
#define LUISA_ASSUME(x) \
if (!(x)) __builtin_unreachable()
#endif
#else
#define LUISA_ASSUME(expression) assert(expression)
#endif
5 changes: 5 additions & 0 deletions include/luisa/dsl/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ inline void unreachable(luisa::string_view msg) noexcept {
detail::FunctionBuilder::current()->call(CallOp::UNREACHABLE, {message});
}

inline ULong device_clock() noexcept {
return def<ulong>(detail::FunctionBuilder::current()->call(
Type::of<ulong>(), CallOp::CLOCK, {}));
}

/// Call assert in device code
inline void device_assert(Expr<bool> pred) noexcept {
detail::FunctionBuilder::current()->call(
Expand Down
136 changes: 69 additions & 67 deletions include/luisa/runtime/command_list.h
Original file line number Diff line number Diff line change
@@ -1,67 +1,69 @@
#pragma once

#include <luisa/core/concepts.h>
#include <luisa/core/stl/optional.h>
#include <luisa/core/stl/functional.h>
#include <luisa/runtime/rhi/command.h>

#ifdef LUISA_ENABLE_API
#include <luisa/api/common.h>
#endif
namespace lc::validation {
class Device;
}// namespace lc::validation
namespace luisa::compute {

class LC_RUNTIME_API CommandList : concepts::Noncopyable {
friend class lc::validation::Device;

public:
class Commit;
using CommandContainer = luisa::vector<luisa::unique_ptr<Command>>;
using CallbackContainer = luisa::vector<luisa::move_only_function<void()>>;

private:
CommandContainer _commands;
CallbackContainer _callbacks;
bool _committed{false};

public:
CommandList() noexcept = default;
~CommandList() noexcept;
CommandList(CommandList &&another) noexcept;
CommandList &operator=(CommandList &&rhs) noexcept = delete;
[[nodiscard]] static CommandList create(size_t reserved_command_size = 0u,
size_t reserved_callback_size = 0u) noexcept;

void reserve(size_t command_size, size_t callback_size) noexcept;
CommandList &operator<<(luisa::unique_ptr<Command> &&cmd) noexcept;
CommandList &append(luisa::unique_ptr<Command> &&cmd) noexcept;
CommandList &add_callback(luisa::move_only_function<void()> &&callback) noexcept;
void clear() noexcept;
[[nodiscard]] auto commands() const noexcept { return luisa::span{_commands}; }
[[nodiscard]] auto callbacks() const noexcept { return luisa::span{_callbacks}; }
[[nodiscard]] CommandContainer steal_commands() noexcept;
[[nodiscard]] CallbackContainer steal_callbacks() noexcept;
[[nodiscard]] auto empty() const noexcept { return _commands.empty() && _callbacks.empty(); }
[[nodiscard]] Commit commit() noexcept;
};

class CommandList::Commit {

private:
CommandList _list;

private:
friend class CommandList;
explicit Commit(CommandList &&list) noexcept
: _list{std::move(list)} {}
Commit(Commit &&) noexcept = default;

public:
Commit &operator=(Commit &&) noexcept = delete;
Commit &operator=(const Commit &) noexcept = delete;
[[nodiscard]] auto command_list() && noexcept { return std::move(_list); }
};

}// namespace luisa::compute
#pragma once

#include <luisa/core/concepts.h>
#include <luisa/core/stl/optional.h>
#include <luisa/core/stl/functional.h>
#include <luisa/runtime/rhi/command.h>

#ifdef LUISA_ENABLE_API
#include <luisa/api/common.h>
#endif

namespace lc::validation {
class Device;
}// namespace lc::validation

namespace luisa::compute {

class LC_RUNTIME_API CommandList : concepts::Noncopyable {
friend class lc::validation::Device;

public:
class Commit;
using CommandContainer = luisa::vector<luisa::unique_ptr<Command>>;
using CallbackContainer = luisa::vector<luisa::move_only_function<void()>>;

private:
CommandContainer _commands;
CallbackContainer _callbacks;
bool _committed{false};

public:
CommandList() noexcept = default;
~CommandList() noexcept;
CommandList(CommandList &&another) noexcept;
CommandList &operator=(CommandList &&rhs) noexcept = delete;
[[nodiscard]] static CommandList create(size_t reserved_command_size = 0u,
size_t reserved_callback_size = 0u) noexcept;

void reserve(size_t command_size, size_t callback_size) noexcept;
CommandList &operator<<(luisa::unique_ptr<Command> &&cmd) noexcept;
CommandList &append(luisa::unique_ptr<Command> &&cmd) noexcept;
CommandList &add_callback(luisa::move_only_function<void()> &&callback) noexcept;
void clear() noexcept;
[[nodiscard]] auto commands() const noexcept { return luisa::span{_commands}; }
[[nodiscard]] auto callbacks() const noexcept { return luisa::span{_callbacks}; }
[[nodiscard]] CommandContainer steal_commands() noexcept;
[[nodiscard]] CallbackContainer steal_callbacks() noexcept;
[[nodiscard]] auto empty() const noexcept { return _commands.empty() && _callbacks.empty(); }
[[nodiscard]] Commit commit() noexcept;
};

class CommandList::Commit {

private:
CommandList _list;

private:
friend class CommandList;
explicit Commit(CommandList &&list) noexcept
: _list{std::move(list)} {}
Commit(Commit &&) noexcept = default;

public:
Commit &operator=(Commit &&) noexcept = delete;
Commit &operator=(const Commit &) noexcept = delete;
[[nodiscard]] auto command_list() && noexcept { return std::move(_list); }
};

}// namespace luisa::compute
1 change: 1 addition & 0 deletions include/luisa/runtime/rhi/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ class AccelBuildCommand final : public Command {
[[nodiscard]] auto request() const noexcept { return _request; }
[[nodiscard]] auto instance_count() const noexcept { return _instance_count; }
[[nodiscard]] auto modifications() const noexcept { return luisa::span{_modifications}; }
[[nodiscard]] auto steal_modifications() noexcept { return std::move(_modifications); }
[[nodiscard]] auto update_instance_buffer_only() const noexcept { return _update_instance_buffer_only; }
LUISA_MAKE_COMMAND_COMMON(StreamTag::COMPUTE)
};
Expand Down
1 change: 0 additions & 1 deletion include/luisa/runtime/rhi/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ struct SwapchainCreationInfo : public ResourceCreationInfo {
};

struct ShaderCreationInfo : public ResourceCreationInfo {
// luisa::string name;
uint3 block_size;

[[nodiscard]] static auto make_invalid() noexcept {
Expand Down
2 changes: 2 additions & 0 deletions include/luisa/xir/ilist.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,15 @@ class IntrusiveNode : public Base {
assert(!is_head_sentinel() && "Inserting before a head sentinel.");
node->_prev = _prev;
node->_next = static_cast<T *>(this);
_prev->_next = node;
_prev = node;
}
virtual void insert_after_self(T *node) noexcept {
assert(!node->is_linked() && "Inserting a linked node into a list.");
assert(!is_tail_sentinel() && "Inserting after a tail sentinel.");
node->_next = _next;
node->_prev = static_cast<T *>(this);
_next->_prev = node;
_next = node;
}
};
Expand Down
17 changes: 9 additions & 8 deletions include/luisa/xir/instructions/intrinsic.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ enum struct IntrinsicOp {
BINDLESS_TEXTURE2D_SAMPLE, // (bindless_array, index: uint, uv: float2): float4
BINDLESS_TEXTURE2D_SAMPLE_LEVEL, // (bindless_array, index: uint, uv: float2, level: float): float4
BINDLESS_TEXTURE2D_SAMPLE_GRAD, // (bindless_array, index: uint, uv: float2, ddx: float2, ddy: float2): float4
BINDLESS_TEXTURE2D_SAMPLE_GRAD_LEVEL,// (bindless_array, index: uint, uv: float2, ddx: float2, ddy: float2, mip_clamp: float): float4
BINDLESS_TEXTURE2D_SAMPLE_GRAD_LEVEL,// (bindless_array, index: uint, uv: float2, ddx: float2, ddy: float2, mip_clamp: float): float4
BINDLESS_TEXTURE3D_SAMPLE, // (bindless_array, index: uint, uv: float3): float4
BINDLESS_TEXTURE3D_SAMPLE_LEVEL, // (bindless_array, index: uint, uv: float3, level: float): float4
BINDLESS_TEXTURE3D_SAMPLE_GRAD, // (bindless_array, index: uint, uv: float3, ddx: float3, ddy: float3): float4
BINDLESS_TEXTURE3D_SAMPLE_GRAD_LEVEL,// (bindless_array, index: uint, uv: float3, ddx: float3, ddy: float3, mip_clamp: float): float4
BINDLESS_TEXTURE3D_SAMPLE_GRAD_LEVEL,// (bindless_array, index: uint, uv: float3, ddx: float3, ddy: float3, mip_clamp: float): float4

BINDLESS_TEXTURE2D_SAMPLE_SAMPLER, // (bindless_array, index: uint, uv: float2, filter: uint, level: uint): float4
BINDLESS_TEXTURE2D_SAMPLE_LEVEL_SAMPLER, // (bindless_array, index: uint, uv: float2, level: float, filter: uint, level: uint): float4
Expand All @@ -208,8 +208,6 @@ enum struct IntrinsicOp {
BINDLESS_BUFFER_READ, // (bindless_array, index: uint, elem_index: uint) -> T
BINDLESS_BUFFER_WRITE,// (bindless_array, index: uint, elem_index: uint, value: T) -> void
BINDLESS_BUFFER_SIZE, // (bindless_array, index: uint, stride: uint) -> size: uint64
BINDLESS_BUFFER_TYPE, // (bindless_array, index: uint) -> uint64 (type id of the element); the returned value
// could be compared with the value of a TypeIDExpr to examine the type of the buffer

BINDLESS_BYTE_BUFFER_READ, // (bindless_array, index: uint, offset_bytes: uint64) -> T
BINDLESS_BYTE_BUFFER_WRITE,// (bindless_array, index: uint, offset_bytes: uint64, value: T) -> void
Expand Down Expand Up @@ -240,10 +238,10 @@ enum struct IntrinsicOp {
RAY_TRACING_INSTANCE_USER_ID, // (Accel, uint)
RAY_TRACING_INSTANCE_VISIBILITY_MASK,// (Accel, uint)

RAY_TRACING_SET_INSTANCE_TRANSFORM, // (Accel, uint, float4x4)
RAY_TRACING_SET_INSTANCE_VISIBILITY,// (Accel, uint, uint)
RAY_TRACING_SET_INSTANCE_OPACITY, // (Accel, uint, bool)
RAY_TRACING_SET_INSTANCE_USER_ID, // (Accel, uint, uint)
RAY_TRACING_SET_INSTANCE_TRANSFORM, // (Accel, uint, float4x4)
RAY_TRACING_SET_INSTANCE_VISIBILITY_MASK,// (Accel, uint, uint)
RAY_TRACING_SET_INSTANCE_OPACITY, // (Accel, uint, bool)
RAY_TRACING_SET_INSTANCE_USER_ID, // (Accel, uint, uint)

RAY_TRACING_TRACE_CLOSEST,// (Accel, ray, mask: uint): TriangleHit
RAY_TRACING_TRACE_ANY, // (Accel, ray, mask: uint): bool
Expand Down Expand Up @@ -307,6 +305,9 @@ enum struct IntrinsicOp {

// shader execution re-ordering
SHADER_EXECUTION_REORDER,// (uint hint, uint hint_bits): void

// clock
CLOCK,// (): uint64
};

[[nodiscard]] LC_XIR_API luisa::string to_string(IntrinsicOp op) noexcept;
Expand Down
19 changes: 19 additions & 0 deletions include/luisa/xir/passes/outline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <luisa/core/stl/unordered_map.h>
#include <luisa/xir/module.h>
#include <luisa/xir/instructions/outline.h>

namespace luisa::compute::xir {

// This pass will outline all outline instructions in the module.
// Information about the outlined functions will be returned.

struct OutlineInfo {
luisa::unordered_map<OutlineInst *, Function *> outlines;
};

LC_XIR_API OutlineInfo outline_pass_run_on_function(Module *module, Function *function) noexcept;
LC_XIR_API OutlineInfo outline_pass_run_on_module(Module *module) noexcept;

}// namespace luisa::compute::xir
Loading

0 comments on commit 1c73a3b

Please sign in to comment.