Skip to content

Commit

Permalink
Use fully-qualified namespaces for all Kompute objects
Browse files Browse the repository at this point in the history
Even if they are already in the kp namespace.
Add a script to make these changes automatically.

Signed-off-by: Robert Quill <robert.quill@imgtec.com>
  • Loading branch information
robquill committed Aug 16, 2024
1 parent 40f9adf commit d4f8da9
Show file tree
Hide file tree
Showing 20 changed files with 341 additions and 299 deletions.
26 changes: 26 additions & 0 deletions scripts/fully_qualify_namespaces.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Run this from the src directory

filepath="/path/to/file.txt"
filename=$(basename "$filepath")

# Get the class names from each .hpp file.
# Assumes that the name of the header file is also the class name
# and that the class name is a top-level class that belongs in the
# kp namespace.
for file in $(find . -name "*.hpp"); do
class_name=$(basename "$file" .hpp)
echo "$class_name"

# Replace anything where the class name is used as a template argument
find . \( -name "*.cpp" -o -name "*.hpp" \) -exec sed -i s/\<"$class_name"/\<kp::$class_name/g {} +

# Replace anything where a member of the class is accessed using ::
find . \( -name "*.cpp" -o -name "*.hpp" \) -exec sed -i "s/\(^\|[^:]\)\($class_name::\)/\1kp::\2/g" {} +
done

# Special cases
find \( -name "*.cpp" -o -name "*.hpp" \) -exec sed -i 's/\(^\|[^:]\)\(TensorT<\)/\1kp::\2/g' {} +
find \( -name "*.cpp" -o -name "*.hpp" \) -exec sed -i 's/\(^\|[^:]\)\(TensorTypes::\)/\1kp::Tensor::\2/g' {} +
find \( -name "*.cpp" -o -name "*.hpp" \) -exec sed -i 's/\(^\|[^:]\)\(TensorDataTypes::\)/\1kp::Tensor::\2/g' {} +
26 changes: 13 additions & 13 deletions src/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@

namespace kp {

Algorithm::~Algorithm()
kp::Algorithm::~Algorithm()
{
KP_LOG_DEBUG("Kompute Algorithm Destructor started");

this->destroy();
}

bool
Algorithm::isInit()
kp::Algorithm::isInit()
{
return this->mPipeline && this->mPipelineCache && this->mPipelineLayout &&
this->mDescriptorPool && this->mDescriptorSet &&
this->mDescriptorSetLayout && this->mShaderModule;
}

void
Algorithm::destroy()
kp::Algorithm::destroy()
{
// We don't have to free memory on destroy as it's freed by the
// commandBuffer destructor if (this->mPushConstantsData) {
Expand Down Expand Up @@ -125,7 +125,7 @@ Algorithm::destroy()
}

void
Algorithm::createParameters()
kp::Algorithm::createParameters()
{
KP_LOG_DEBUG("Kompute Algorithm createParameters started");

Expand Down Expand Up @@ -204,7 +204,7 @@ Algorithm::createParameters()
}

void
Algorithm::createShaderModule()
kp::Algorithm::createShaderModule()
{
KP_LOG_DEBUG("Kompute Algorithm createShaderModule started");

Expand All @@ -225,7 +225,7 @@ Algorithm::createShaderModule()
}

void
Algorithm::createPipeline()
kp::Algorithm::createPipeline()
{
KP_LOG_DEBUG("Kompute Algorithm calling create Pipeline");

Expand Down Expand Up @@ -321,7 +321,7 @@ Algorithm::createPipeline()
}

void
Algorithm::recordBindCore(const vk::CommandBuffer& commandBuffer)
kp::Algorithm::recordBindCore(const vk::CommandBuffer& commandBuffer)
{
KP_LOG_DEBUG("Kompute Algorithm binding pipeline");

Expand All @@ -339,7 +339,7 @@ Algorithm::recordBindCore(const vk::CommandBuffer& commandBuffer)
}

void
Algorithm::recordBindPush(const vk::CommandBuffer& commandBuffer)
kp::Algorithm::recordBindPush(const vk::CommandBuffer& commandBuffer)
{
if (this->mPushConstantsSize) {
KP_LOG_DEBUG("Kompute Algorithm binding push constants memory size: {}",
Expand All @@ -356,7 +356,7 @@ Algorithm::recordBindPush(const vk::CommandBuffer& commandBuffer)
}

void
Algorithm::recordDispatch(const vk::CommandBuffer& commandBuffer)
kp::Algorithm::recordDispatch(const vk::CommandBuffer& commandBuffer)
{
KP_LOG_DEBUG("Kompute Algorithm recording dispatch");

Expand All @@ -365,7 +365,7 @@ Algorithm::recordDispatch(const vk::CommandBuffer& commandBuffer)
}

void
Algorithm::setWorkgroup(const Workgroup& workgroup, uint32_t minSize)
kp::Algorithm::setWorkgroup(const Workgroup& workgroup, uint32_t minSize)
{

KP_LOG_INFO("Kompute OpAlgoCreate setting dispatch size");
Expand All @@ -389,13 +389,13 @@ Algorithm::setWorkgroup(const Workgroup& workgroup, uint32_t minSize)
}

const Workgroup&
Algorithm::getWorkgroup()
kp::Algorithm::getWorkgroup()
{
return this->mWorkgroup;
}

const std::vector<std::shared_ptr<Tensor>>&
Algorithm::getTensors()
const std::vector<std::shared_ptr<kp::Tensor>>&
kp::Algorithm::getTensors()
{
return this->mTensors;
}
Expand Down
71 changes: 38 additions & 33 deletions src/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ debugMessageCallback(VkDebugReportFlagsEXT /*flags*/,
}
#endif

Manager::Manager()
kp::Manager::Manager()
: Manager(0)
{
}

Manager::Manager(uint32_t physicalDeviceIndex,
const std::vector<uint32_t>& familyQueueIndices,
const std::vector<std::string>& desiredExtensions)
kp::Manager::Manager(uint32_t physicalDeviceIndex,
const std::vector<uint32_t>& familyQueueIndices,
const std::vector<std::string>& desiredExtensions)
{
this->mManageResources = true;

Expand All @@ -53,9 +53,9 @@ Manager::Manager(uint32_t physicalDeviceIndex,
familyQueueIndices, physicalDeviceIndex, desiredExtensions);
}

Manager::Manager(std::shared_ptr<vk::Instance> instance,
std::shared_ptr<vk::PhysicalDevice> physicalDevice,
std::shared_ptr<vk::Device> device)
kp::Manager::Manager(std::shared_ptr<vk::Instance> instance,
std::shared_ptr<vk::PhysicalDevice> physicalDevice,
std::shared_ptr<vk::Device> device)
{
this->mManageResources = false;

Expand All @@ -69,14 +69,14 @@ Manager::Manager(std::shared_ptr<vk::Instance> instance,
#endif
}

Manager::~Manager()
kp::Manager::~Manager()
{
KP_LOG_DEBUG("Kompute Manager Destructor started");
this->destroy();
}

void
Manager::destroy()
kp::Manager::destroy()
{

KP_LOG_DEBUG("Kompute Manager destroy() started");
Expand All @@ -90,8 +90,9 @@ Manager::destroy()
if (this->mManageResources && this->mManagedSequences.size()) {
KP_LOG_DEBUG("Kompute Manager explicitly running destructor for "
"managed sequences");
for (const std::weak_ptr<Sequence>& weakSq : this->mManagedSequences) {
if (std::shared_ptr<Sequence> sq = weakSq.lock()) {
for (const std::weak_ptr<kp::Sequence>& weakSq :
this->mManagedSequences) {
if (std::shared_ptr<kp::Sequence> sq = weakSq.lock()) {
sq->destroy();
}
}
Expand All @@ -100,9 +101,10 @@ Manager::destroy()

if (this->mManageResources && this->mManagedAlgorithms.size()) {
KP_LOG_DEBUG("Kompute Manager explicitly freeing algorithms");
for (const std::weak_ptr<Algorithm>& weakAlgorithm :
for (const std::weak_ptr<kp::Algorithm>& weakAlgorithm :
this->mManagedAlgorithms) {
if (std::shared_ptr<Algorithm> algorithm = weakAlgorithm.lock()) {
if (std::shared_ptr<kp::Algorithm> algorithm =
weakAlgorithm.lock()) {
algorithm->destroy();
}
}
Expand All @@ -111,8 +113,9 @@ Manager::destroy()

if (this->mManageResources && this->mManagedTensors.size()) {
KP_LOG_DEBUG("Kompute Manager explicitly freeing tensors");
for (const std::weak_ptr<Tensor>& weakTensor : this->mManagedTensors) {
if (std::shared_ptr<Tensor> tensor = weakTensor.lock()) {
for (const std::weak_ptr<kp::Tensor>& weakTensor :
this->mManagedTensors) {
if (std::shared_ptr<kp::Tensor> tensor = weakTensor.lock()) {
tensor->destroy();
}
}
Expand Down Expand Up @@ -150,7 +153,7 @@ Manager::destroy()
}

void
Manager::createInstance()
kp::Manager::createInstance()
{

KP_LOG_DEBUG("Kompute Manager creating instance");
Expand Down Expand Up @@ -285,32 +288,34 @@ Manager::createInstance()
}

void
Manager::clear()
kp::Manager::clear()
{
if (this->mManageResources) {
this->mManagedTensors.erase(
std::remove_if(begin(this->mManagedTensors),
end(this->mManagedTensors),
[](std::weak_ptr<Tensor> t) { return t.expired(); }),
std::remove_if(
begin(this->mManagedTensors),
end(this->mManagedTensors),
[](std::weak_ptr<kp::Tensor> t) { return t.expired(); }),
end(this->mManagedTensors));
this->mManagedAlgorithms.erase(
std::remove_if(
begin(this->mManagedAlgorithms),
end(this->mManagedAlgorithms),
[](std::weak_ptr<Algorithm> t) { return t.expired(); }),
[](std::weak_ptr<kp::Algorithm> t) { return t.expired(); }),
end(this->mManagedAlgorithms));
this->mManagedSequences.erase(
std::remove_if(begin(this->mManagedSequences),
end(this->mManagedSequences),
[](std::weak_ptr<Sequence> t) { return t.expired(); }),
std::remove_if(
begin(this->mManagedSequences),
end(this->mManagedSequences),
[](std::weak_ptr<kp::Sequence> t) { return t.expired(); }),
end(this->mManagedSequences));
}
}

void
Manager::createDevice(const std::vector<uint32_t>& familyQueueIndices,
uint32_t physicalDeviceIndex,
const std::vector<std::string>& desiredExtensions)
kp::Manager::createDevice(const std::vector<uint32_t>& familyQueueIndices,
uint32_t physicalDeviceIndex,
const std::vector<std::string>& desiredExtensions)
{

KP_LOG_DEBUG("Kompute Manager creating Device");
Expand Down Expand Up @@ -456,12 +461,12 @@ Manager::createDevice(const std::vector<uint32_t>& familyQueueIndices,
KP_LOG_DEBUG("Kompute Manager compute queue obtained");
}

std::shared_ptr<Sequence>
Manager::sequence(uint32_t queueIndex, uint32_t totalTimestamps)
std::shared_ptr<kp::Sequence>
kp::Manager::sequence(uint32_t queueIndex, uint32_t totalTimestamps)
{
KP_LOG_DEBUG("Kompute Manager sequence() with queueIndex: {}", queueIndex);

std::shared_ptr<Sequence> sq{ new kp::Sequence(
std::shared_ptr<kp::Sequence> sq{ new kp::Sequence(
this->mPhysicalDevice,
this->mDevice,
this->mComputeQueues[queueIndex],
Expand All @@ -476,19 +481,19 @@ Manager::sequence(uint32_t queueIndex, uint32_t totalTimestamps)
}

vk::PhysicalDeviceProperties
Manager::getDeviceProperties() const
kp::Manager::getDeviceProperties() const
{
return this->mPhysicalDevice->getProperties();
}

std::vector<vk::PhysicalDevice>
Manager::listDevices() const
kp::Manager::listDevices() const
{
return this->mInstance->enumeratePhysicalDevices();
}

std::shared_ptr<vk::Instance>
Manager::getVkInstance() const
kp::Manager::getVkInstance() const
{
return this->mInstance;
}
Expand Down
10 changes: 5 additions & 5 deletions src/OpAlgoDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace kp {

OpAlgoDispatch::~OpAlgoDispatch()
kp::OpAlgoDispatch::~OpAlgoDispatch()
{
KP_LOG_DEBUG("Kompute OpAlgoDispatch destructor started");

Expand All @@ -15,12 +15,12 @@ OpAlgoDispatch::~OpAlgoDispatch()
}

void
OpAlgoDispatch::record(const vk::CommandBuffer& commandBuffer)
kp::OpAlgoDispatch::record(const vk::CommandBuffer& commandBuffer)
{
KP_LOG_DEBUG("Kompute OpAlgoDispatch record called");

// Barrier to ensure the data is finished writing to buffer memory
for (const std::shared_ptr<Tensor>& tensor :
for (const std::shared_ptr<kp::Tensor>& tensor :
this->mAlgorithm->getTensors()) {
tensor->recordPrimaryBufferMemoryBarrier(
commandBuffer,
Expand All @@ -43,13 +43,13 @@ OpAlgoDispatch::record(const vk::CommandBuffer& commandBuffer)
}

void
OpAlgoDispatch::preEval(const vk::CommandBuffer& /*commandBuffer*/)
kp::OpAlgoDispatch::preEval(const vk::CommandBuffer& /*commandBuffer*/)
{
KP_LOG_DEBUG("Kompute OpAlgoDispatch preEval called");
}

void
OpAlgoDispatch::postEval(const vk::CommandBuffer& /*commandBuffer*/)
kp::OpAlgoDispatch::postEval(const vk::CommandBuffer& /*commandBuffer*/)
{
KP_LOG_DEBUG("Kompute OpAlgoDispatch postSubmit called");
}
Expand Down
Loading

0 comments on commit d4f8da9

Please sign in to comment.