Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
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
75 changes: 75 additions & 0 deletions src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#include <cstdint>
#include <memory>

#include "QirRuntimeApi_I.hpp"
#include "QubitManager.hpp"
#include "BasicRuntimeDriverFactory.h"

namespace Microsoft
{
namespace Quantum
{
class CBasicRuntimeDriver : public IRuntimeDriver
{
std::unique_ptr<CQubitManager> qubitManager;

public:
CBasicRuntimeDriver()
{
qubitManager = std::make_unique<CQubitManager>();
}

~CBasicRuntimeDriver() override
{
}

std::string QubitToString(QubitIdType q) override
{
return std::to_string(q);
}

QubitIdType AllocateQubit() override
{
return qubitManager->Allocate();
}

void ReleaseQubit(QubitIdType q) override
{
qubitManager->Release(q);
}

void ReleaseResult(Result /* result */) override
{
}

bool AreEqualResults(Result r1, Result r2) override
{
return r1 == r2;
}

ResultValue GetResultValue(Result r) override
{
return (r == UseZero()) ? Result_Zero : Result_One;
}

Result UseZero() override
{
return reinterpret_cast<Result>(0);
}

Result UseOne() override
{
return reinterpret_cast<Result>(1);
}
};

extern "C" void* CreateBasicRuntimeDriver()
{
return (IRuntimeDriver*)new CBasicRuntimeDriver();
}

} // namespace Quantum
} // namespace Microsoft
1 change: 1 addition & 0 deletions src/Qir/Runtime/lib/QIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set(rt_sup_source_files
strings.cpp
utils.cpp
QubitManager.cpp
BasicRuntimeDriver.cpp
)

# Produce object lib we'll use to create a shared lib (so/dll) later on
Expand Down
1 change: 0 additions & 1 deletion src/Qir/Runtime/lib/QSharpFoundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ install(TARGETS Microsoft.Quantum.Qir.QSharp.Foundation
LIBRARY DESTINATION "${CMAKE_BINARY_DIR}/bin"
ARCHIVE DESTINATION "${CMAKE_BINARY_DIR}/bin"
)

21 changes: 21 additions & 0 deletions src/Qir/Runtime/public/BasicRuntimeDriverFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#ifndef BASICRUNTIMEDRIVERFACTORY_H
#define BASICRUNTIMEDRIVERFACTORY_H

#include <stdint.h>
#include "CoreDefines.h"

#ifdef __cplusplus
extern "C"
{
#endif

QIR_SHARED_API void* CreateBasicRuntimeDriver();

#ifdef __cplusplus
} // extern "C"
#endif

#endif // #ifndef BASICRUNTIMEDRIVERFACTORY_H