Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vulkan] Device API explicit semaphores #4852

Merged
merged 21 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2ea6888
Device API explicit semaphores
bobcao3 Apr 23, 2022
3029d37
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 23, 2022
1ffe3f0
fix
bobcao3 Apr 23, 2022
f99b166
Merge branch 'master' of https://github.com/bobcao3/taichi
bobcao3 Apr 23, 2022
2af99ef
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 23, 2022
f767b3d
Destroy the semaphore before the context
bobcao3 Apr 24, 2022
2554deb
Fix type warnings
bobcao3 Apr 24, 2022
73fe3ec
fix nits
bobcao3 Apr 25, 2022
7b966da
return nullptr for devices that don't need semaphores
bobcao3 Apr 25, 2022
a977c03
test out no semaphores between same queue
bobcao3 Apr 26, 2022
d5d508a
Use native command list instead of emulated for dx11
bobcao3 Apr 26, 2022
75116c0
Merge branch 'master' of https://github.com/bobcao3/taichi
bobcao3 Apr 26, 2022
7f51dc8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 26, 2022
e6c86f0
remove the in-queue semaphore
bobcao3 Apr 26, 2022
7fe9a54
Merge branch 'master' of https://github.com/bobcao3/taichi
bobcao3 Apr 26, 2022
630541a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 26, 2022
14c0aaf
Use flush instead of sync in places
bobcao3 Apr 26, 2022
e522bae
Merge branch 'master' of https://github.com/bobcao3/taichi
bobcao3 Apr 26, 2022
6286db7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 26, 2022
2158f20
Fix possible null semaphore
bobcao3 Apr 26, 2022
65dc483
merge
bobcao3 Apr 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions python/taichi/ui/staging_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,21 @@ def copy_image_f32_to_u8(src: ti.template(), dst: ti.template(),
c = src[i, j][k]
c = max(0.0, min(1.0, c))
c = c * 255
dst[i, j][k] = int(c)
dst[i, j][k] = ti.cast(c, ti.u8)
if num_components < 4:
# alpha channel
dst[i, j][3] = 255
dst[i, j][3] = ti.cast(255, ti.u8)


@ti.kernel
def copy_image_u8_to_u8(src: ti.template(), dst: ti.template(),
num_components: ti.template()):
for i, j in src:
for k in ti.static(range(num_components)):
dst[i, j][k] = src[i, j][k]
dst[i, j][k] = ti.cast(src[i, j][k], ti.u8)
if num_components < 4:
# alpha channel
dst[i, j][3] = 255
dst[i, j][3] = ti.cast(255, ti.u8)


# ggui renderer always assumes the input image to be u8 RGBA
Expand Down
3 changes: 3 additions & 0 deletions taichi/aot/module_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ class TargetDevice : public Device {
Stream *get_compute_stream() override {
TI_NOT_IMPLEMENTED;
}
void wait_idle() override {
TI_NOT_IMPLEMENTED;
}
};

} // namespace aot
Expand Down
11 changes: 9 additions & 2 deletions taichi/backends/cpu/cpu_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ class CpuStream : public Stream {
~CpuStream() override{};

std::unique_ptr<CommandList> new_command_list() override{TI_NOT_IMPLEMENTED};
void submit(CommandList *cmdlist) override{TI_NOT_IMPLEMENTED};
void submit_synced(CommandList *cmdlist) override{TI_NOT_IMPLEMENTED};
StreamSemaphore submit(CommandList *cmdlist,
const std::vector<StreamSemaphore> &wait_semaphores =
{}) override{TI_NOT_IMPLEMENTED};
StreamSemaphore submit_synced(
CommandList *cmdlist,
const std::vector<StreamSemaphore> &wait_semaphores = {}) override{
TI_NOT_IMPLEMENTED};

void command_sync() override{TI_NOT_IMPLEMENTED};
};
Expand Down Expand Up @@ -111,6 +116,8 @@ class CpuDevice : public LlvmDevice {

Stream *get_compute_stream() override{TI_NOT_IMPLEMENTED};

void wait_idle() override{TI_NOT_IMPLEMENTED};

private:
std::vector<AllocInfo> allocations_;
std::unordered_map<int, std::unique_ptr<VirtualMemoryAllocator>>
Expand Down
11 changes: 9 additions & 2 deletions taichi/backends/cuda/cuda_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ class CudaStream : public Stream {
~CudaStream() override{};

std::unique_ptr<CommandList> new_command_list() override{TI_NOT_IMPLEMENTED};
void submit(CommandList *cmdlist) override{TI_NOT_IMPLEMENTED};
void submit_synced(CommandList *cmdlist) override{TI_NOT_IMPLEMENTED};
StreamSemaphore submit(CommandList *cmdlist,
const std::vector<StreamSemaphore> &wait_semaphores =
{}) override{TI_NOT_IMPLEMENTED};
StreamSemaphore submit_synced(
CommandList *cmdlist,
const std::vector<StreamSemaphore> &wait_semaphores = {}) override{
TI_NOT_IMPLEMENTED};

void command_sync() override{TI_NOT_IMPLEMENTED};
};
Expand Down Expand Up @@ -123,6 +128,8 @@ class CudaDevice : public LlvmDevice {

Stream *get_compute_stream() override{TI_NOT_IMPLEMENTED};

void wait_idle() override{TI_NOT_IMPLEMENTED};

private:
std::vector<AllocInfo> allocations_;
void validate_device_alloc(const DeviceAllocation alloc) {
Expand Down
26 changes: 22 additions & 4 deletions taichi/backends/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,26 @@ inline bool operator&(AllocUsage a, AllocUsage b) {
return static_cast<int>(a) & static_cast<int>(b);
}

class StreamSemaphoreObject {
bobcao3 marked this conversation as resolved.
Show resolved Hide resolved
public:
virtual ~StreamSemaphoreObject() {
}
};

using StreamSemaphore = std::shared_ptr<StreamSemaphoreObject>;

class Stream {
public:
virtual ~Stream(){};
virtual ~Stream() {
}

virtual std::unique_ptr<CommandList> new_command_list() = 0;
virtual void submit(CommandList *cmdlist) = 0;
virtual void submit_synced(CommandList *cmdlist) = 0;
virtual StreamSemaphore submit(
CommandList *cmdlist,
const std::vector<StreamSemaphore> &wait_semaphores = {}) = 0;
virtual StreamSemaphore submit_synced(
CommandList *cmdlist,
const std::vector<StreamSemaphore> &wait_semaphores = {}) = 0;

virtual void command_sync() = 0;
};
Expand Down Expand Up @@ -457,6 +470,9 @@ class Device {
// Each thraed will acquire its own stream
virtual Stream *get_compute_stream() = 0;

// Wait for all tasks to complete (task from all streams)
virtual void wait_idle() = 0;

// Mapping can fail and will return nullptr
virtual void *map_range(DevicePtr ptr, uint64_t size) = 0;
virtual void *map(DeviceAllocation alloc) = 0;
Expand Down Expand Up @@ -498,8 +514,10 @@ class Surface {
virtual ~Surface() {
}

virtual StreamSemaphore acquire_next_image() = 0;
virtual DeviceAllocation get_target_image() = 0;
virtual void present_image() = 0;
virtual void present_image(
const std::vector<StreamSemaphore> &wait_semaphores = {}) = 0;
virtual std::pair<uint32_t, uint32_t> get_size() = 0;
virtual int get_image_count() = 0;
virtual BufferFormat image_format() = 0;
Expand Down
Loading