Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions mooncake-store/include/device/accelerator_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ class AcceleratorDevice {
virtual void SetContext(int32_t device_id) const = 0;
virtual bool Copy(void* dst, const void* src, size_t size,
CopyDirection direction) const = 0;
// Batched copies. CopyAsync starts a copy on the current context that
// may still be running when it returns; Synchronize waits for every copy
// this thread started with CopyAsync and returns false if any failed.
// After any CopyAsync, including a failed one, call Synchronize before
// the buffers are reused or freed. The default runs Copy synchronously.
virtual bool CopyAsync(void* dst, const void* src, size_t size,
CopyDirection direction) const {
return Copy(dst, src, size, direction);
}
virtual bool Synchronize() const { return true; }
virtual PinnedHostBuffer AllocatePinnedHost(size_t size) const = 0;
};

Expand Down
65 changes: 65 additions & 0 deletions mooncake-store/include/device/xpu_accelerator_device_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#pragma once

// Internals of the Intel XPU accelerator device that unit tests reach
// directly: the owner-device lookup and a copy fault-injection hook.

#include <cstddef>
#include <cstdint>
#include <functional>
#include <mutex>
#include <unordered_set>
#include <vector>

namespace mooncake {
namespace device {
namespace xpu {

// DeviceIndexOf results that are not a queue index.
inline constexpr int kNotDeviceMemory = -1;
// USM device memory owned by a GPU the runtime did not enumerate (for example
// one without usm_device_allocations). No queue is known to be able to copy
// it, so copies touching it fail instead of running on another device.
inline constexpr int kUnsupportedDevice = -2;

// Index of `owner` in `devices`, the GPUs that have a queue, or
// kUnsupportedDevice when it is not one of them.
template <typename Device>
int OwnerQueueIndex(const Device& owner, const std::vector<Device>& devices) {
for (size_t i = 0; i < devices.size(); ++i) {
if (devices[i] == owner) return static_cast<int>(i);
}
return kUnsupportedDevice;
}

// Remembers which keys were already reported, so a warning is logged once
// per key. Only reached on an error path, so the mutex is not hot.
template <typename Key, typename Hash = std::hash<Key>>
class OncePerKey {
public:
// True the first time `key` is seen.
bool First(const Key& key) {
std::lock_guard<std::mutex> lock(mu_);
return seen_.insert(key).second;
}

private:
std::mutex mu_;
std::unordered_set<Key, Hash> seen_;
};

namespace testing {

enum class CopyFault {
kNone,
kSyclError, // the submission throws sycl::exception
kBadAlloc, // the submission throws std::bad_alloc
};

// Test only: make the copy submitted `skip` submissions from now, on any
// thread, throw `fault` instead of starting. kNone cancels a pending fault.
void InjectCopyFault(CopyFault fault, int64_t skip = 0);

} // namespace testing
} // namespace xpu
} // namespace device
} // namespace mooncake
10 changes: 10 additions & 0 deletions mooncake-store/include/transfer_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,16 @@ struct MemcpyTask {
: operations(std::move(ops)), state(std::move(s)) {}
};

/**
* @brief True when some op writes bytes that another op of the task reads or
* writes, so the ops must run one after another instead of being batched.
*
* Zero-length ops touch nothing. An op whose own source and destination
* overlap counts too, and so does a range whose end would wrap past the top of
* the address space; both are conservative.
*/
bool MemcpyOperationsOverlap(const std::vector<MemcpyOperation>& operations);

/**
* @brief Thread pool for asynchronous memcpy operations
*
Expand Down
Loading
Loading