From 4f37e20f285e4df00808639bc4f192a04bff8f04 Mon Sep 17 00:00:00 2001 From: Shuli Shu <08cnbj@gmail.com> Date: Tue, 8 Oct 2024 19:04:26 +0000 Subject: [PATCH 01/66] initial commit --- .../lightning_gpu/StateVectorCudaManaged.hpp | 413 ++++++++++++------ .../lightning_gpu/bindings/LGPUBindings.hpp | 51 ++- .../lightning_gpu/_state_vector.py | 27 +- .../lightning_gpu/lightning_gpu.py | 1 + 4 files changed, 354 insertions(+), 138 deletions(-) diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp index 9e68592df..67427f969 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp @@ -352,17 +352,17 @@ class StateVectorCudaManaged } else if (opName == "GlobalPhase") { globalPhaseStateVector(adjoint, params[0]); } else if (native_gates_.find(opName) != native_gates_.end()) { - applyParametricPauliGate({opName}, ctrls, tgts, params.front(), - adjoint); + applyParametricPauliGate_({opName}, ctrls, tgts, params.front(), + adjoint); } else if (opName == "Rot" || opName == "CRot") { if (adjoint) { auto rot_matrix = cuGates::getRot(params[2], params[1], params[0]); - applyDeviceMatrixGate(rot_matrix.data(), ctrls, tgts, true); + applyDeviceMatrixGate_(rot_matrix.data(), ctrls, tgts, true); } else { auto rot_matrix = cuGates::getRot(params[0], params[1], params[2]); - applyDeviceMatrixGate(rot_matrix.data(), ctrls, tgts, false); + applyDeviceMatrixGate_(rot_matrix.data(), ctrls, tgts, false); } } else if (opName == "Matrix") { DataBuffer d_matrix{ @@ -375,8 +375,8 @@ class StateVectorCudaManaged ctrls.rend()}; const std::vector tgts_local{tgts.rbegin(), tgts.rend()}; - applyDeviceMatrixGate(d_matrix.getData(), ctrls_local, tgts_local, - adjoint); + applyDeviceMatrixGate_(d_matrix.getData(), ctrls_local, tgts_local, + adjoint); } else if (par_gates_.find(opName) != par_gates_.end()) { par_gates_.at(opName)(wires, adjoint, params); } else { // No offloadable function call; defer to matrix passing @@ -395,7 +395,7 @@ class StateVectorCudaManaged } else if (!gate_cache_.gateExists(opName, par[0])) { gate_cache_.add_gate(opName, par[0], gate_matrix); } - applyDeviceMatrixGate( + applyDeviceMatrixGate_( gate_cache_.get_gate_device_ptr(opName, par[0]), ctrls_local, tgts_local, adjoint); } @@ -405,27 +405,141 @@ class StateVectorCudaManaged * @brief Apply a single gate to the state vector. * * @param opName Name of gate to apply. - * @param controlled_wires Control wires. - * @param controlled_values Control values (false or true). - * @param wires Wires to apply gate to. - * @param inverse Indicates whether to use adjoint of gate. + * @param ctrls Control wires. + * @param ctrls_values Control values (false or true). + * @param tgts Wires to apply gate to. + * @param adjoint Indicates whether to use adjoint of gate. * @param params Optional parameter list for parametric gates. - * @param params Optional std gate matrix if opName doesn't exist. + * @param gate_matrix Optional gate matrix vector on the host if opName + * doesn't exist. */ - template