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

Update lightning_kokkos_catalyst CUDA target to work with Catalyst #942

Merged
merged 11 commits into from
Nov 7, 2024
5 changes: 4 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@

### Improvements

* Update `lightning_kokkos_catalyst` CUDA target to work with Catalyst.
[(#942)](https://github.com/PennyLaneAI/pennylane-lightning/pull/942)

* Fix PTM stable-latest.
[(#961)](https://github.com/PennyLaneAI/pennylane-lightning/pull/961)

Expand All @@ -69,7 +72,7 @@

* Add zero-state initialization to both `StateVectorCudaManaged` and `StateVectorCudaMPI` constructors to remove the `reset_state` in the python layer ctor and refactor `setBasisState(state, wires)` in the C++ layer.
[(#933)](https://github.com/PennyLaneAI/pennylane-lightning/pull/933)

* The `generate_samples` methods of lightning.{qubit/kokkos} can now take in a seed number to make the generated samples deterministic. This can be useful when, among other things, fixing flaky tests in CI.
[(#927)](https://github.com/PennyLaneAI/pennylane-lightning/pull/927)

Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.39.0-dev51"
__version__ = "0.39.0-dev52"
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ else()
endforeach()

# Fetching include hpp headers
set(INCLUDE_HEADERS DataView.hpp
Exception.hpp
set(INCLUDE_HEADERS Exception.hpp
DataView.hpp
QuantumDevice.hpp
RuntimeCAPI.h
Types.h
Expand All @@ -73,19 +73,40 @@ else()

endif()

if(Kokkos_ENABLE_CUDA)
message(STATUS "Kokkos_ENABLE_CUDA is ON")

# KOKKOS_CUDA_OPTIONS:
# - disable_malloc_async: Disable asynchronous memory allocation to ensure
# that memory operations complete before proceeding.
# - enable_lambda: Allow the use of lambda expressions in parallel
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
# execution policies, used in LK kernel functors, and this flag is
# required when calling those functors from an external library.
# It's supported starting from NVCC v7.0.
# - enable_constexpr: Enable compile-time evaluations for constants.
# There are some undefined behaviour when executing end-to-end Catalyst
# programs related to the value of `constexpr`s in the definition of gate kernels.
# This flag should be enforced for NVCC v7.5+.
if(NVCC_VERSION VERSION_LESS "7.0")
message(WARNING "Building lightning_kokkos_catalyst without lambda and constexpr support.")
target_compile_definitions(lightning_kokkos_catalyst PRIVATE KOKKOS_CUDA_OPTIONS="disable_malloc_async")
elseif(NVCC_VERSION VERSION_LESS "7.5")
message(WARNING "Building lightning_kokkos_catalyst without constexpr support.")
target_compile_definitions(lightning_kokkos_catalyst PRIVATE KOKKOS_CUDA_OPTIONS="disable_malloc_async enable_lambda")
else()
target_compile_definitions(lightning_kokkos_catalyst PRIVATE
KOKKOS_CUDA_OPTIONS="disable_malloc_async enable_lambda enable_constexpr"
)
endif()
endif()

target_include_directories(lightning_kokkos_catalyst INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(lightning_kokkos_catalyst PUBLIC lightning_compile_options
lightning_external_libs
lightning_base
lightning_gates
lightning_utils
lightning_kokkos
lightning_kokkos_algorithms
lightning_kokkos_gates
lightning_kokkos_measurements
lightning_kokkos_utils
)


if (BUILD_TESTS)
enable_testing()
add_subdirectory("tests")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

#pragma once

#define __device_lightning_kokkos

#include <bitset>
#include <cmath>
#include <cstdint>
Expand Down Expand Up @@ -62,7 +60,8 @@ class LightningKokkosSimulator final : public Catalyst::Runtime::QuantumDevice {
Catalyst::Runtime::CacheManager<Kokkos::complex<double>> cache_manager{};
bool tape_recording{false};

std::size_t device_shots;
// set default to avoid C++ tests segfaults in analytic mode
std::size_t device_shots{0};

std::mt19937 *gen{nullptr};

Expand Down Expand Up @@ -99,13 +98,14 @@ class LightningKokkosSimulator final : public Catalyst::Runtime::QuantumDevice {
auto GenerateSamples(size_t shots) -> std::vector<size_t>;

public:
explicit LightningKokkosSimulator(const std::string &kwargs = "{}") {
explicit LightningKokkosSimulator(
const std::string &kwargs = "{}") noexcept {
auto &&args = Catalyst::Runtime::parse_kwargs(kwargs);
device_shots = args.contains("shots")
? static_cast<std::size_t>(std::stoll(args["shots"]))
: 0;
}
~LightningKokkosSimulator() = default;
~LightningKokkosSimulator() noexcept = default;

LightningKokkosSimulator(const LightningKokkosSimulator &) = delete;
LightningKokkosSimulator &
Expand Down
Loading