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
44 changes: 44 additions & 0 deletions include/API/CommandBuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//===- CommandBuffer.h - Offload Command Buffer API -----------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
//
//===----------------------------------------------------------------------===//

#ifndef OFFLOADTEST_API_COMMANDBUFFER_H
#define OFFLOADTEST_API_COMMANDBUFFER_H

#include "API/API.h"

#include <cassert>

namespace offloadtest {

class CommandBuffer {
GPUAPI API;

public:
explicit CommandBuffer(GPUAPI API) : API(API) {}
virtual ~CommandBuffer() = default;
CommandBuffer(const CommandBuffer &) = delete;
CommandBuffer &operator=(const CommandBuffer &) = delete;

GPUAPI getAPI() const { return API; }

template <typename T> T &as() {
assert(API == T::BackendAPI && "CommandBuffer backend mismatch");
return static_cast<T &>(*this);
}
template <typename T> const T &as() const {
assert(API == T::BackendAPI && "CommandBuffer backend mismatch");
return static_cast<const T &>(*this);
}
};

} // namespace offloadtest

#endif // OFFLOADTEST_API_COMMANDBUFFER_H
21 changes: 21 additions & 0 deletions include/API/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

#include "API/API.h"
#include "API/Capabilities.h"
#include "API/CommandBuffer.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Support/Error.h"

#include <memory>
#include <string>
Expand Down Expand Up @@ -60,6 +62,19 @@ class Queue {
public:
virtual ~Queue() = 0;

/// Submit command buffers for execution and block until completion.
// TODO: Return a Fence instead of blocking, once the Fence abstraction
// from PR #1007 is available.
virtual llvm::Error
submit(llvm::SmallVector<std::unique_ptr<CommandBuffer>> CBs) = 0;

/// Convenience overload for submitting a single command buffer.
llvm::Error submit(std::unique_ptr<CommandBuffer> CB) {
llvm::SmallVector<std::unique_ptr<CommandBuffer>> CBs;
CBs.push_back(std::move(CB));
return submit(std::move(CBs));
}

protected:
Queue() = default;
};
Expand All @@ -82,6 +97,12 @@ class Device {
size_t SizeInBytes) = 0;
virtual void printExtra(llvm::raw_ostream &OS) {}

virtual llvm::Expected<std::unique_ptr<CommandBuffer>> createCommandBuffer() {
return llvm::createStringError(
std::errc::not_supported,
"createCommandBuffer not implemented for this backend");
}

virtual ~Device() = 0;

llvm::StringRef getDescription() const { return Description; }
Expand Down
Loading
Loading