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

GPU custom kernels #107

Merged
merged 25 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ec6df36
make sure the custom operator compiles for GPU
scarrazza Jun 4, 2020
662435e
reorganizing structures in order to allocate kernels
scarrazza Jun 4, 2020
c0dd6b6
applygate ncontrols
scarrazza Jun 5, 2020
ef54147
adding x, y, z, zpow operators for no control
scarrazza Jun 5, 2020
54161a3
converting controls from input to attribute
scarrazza Jun 5, 2020
0b97951
implementing ncontrols > 0
scarrazza Jun 5, 2020
f4a806e
adding virtual auxiliary functions for cuda
scarrazza Jun 5, 2020
f0a706d
simplifying apply_gate cuda kernel
scarrazza Jun 5, 2020
88bfb09
conclusing one qubits gates
scarrazza Jun 6, 2020
565c6bc
updating functor signature
scarrazza Jun 6, 2020
4ed0bf8
applying changes
scarrazza Jun 6, 2020
18f29f0
implementing two qubit gates kernels
scarrazza Jun 6, 2020
bd4b86b
apply fix to two qubits gates kernel bug
scarrazza Jun 6, 2020
3a68e23
applying google formatting style
scarrazza Jun 6, 2020
ba5a093
Merge branch 'master' into gpukernels
scarrazza Jun 7, 2020
0d3224b
fixing merge bug
scarrazza Jun 7, 2020
0d35872
use custom gates for CPU and GPU
scarrazza Jun 7, 2020
f7743ac
fixing test measurements with GPU reference numbers
scarrazza Jun 7, 2020
8d516cf
fixing test measurements round 2
scarrazza Jun 7, 2020
ea3ae08
fixing two gate bug
scarrazza Jun 7, 2020
f14392e
Merge branch 'master' into gpukernels
scarrazza Jun 8, 2020
0a497e8
sync CPU operators with master
scarrazza Jun 8, 2020
27a6a4e
removing unused variable
scarrazza Jun 8, 2020
7ec58b0
porting updated CPU gates to GPU
scarrazza Jun 8, 2020
0ff72d2
fixing two gate base
scarrazza Jun 8, 2020
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
8 changes: 1 addition & 7 deletions src/qibo/gates.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from qibo.config import BACKEND_NAME
if BACKEND_NAME == "tensorflow":
import tensorflow as tf
if tf.config.list_physical_devices("GPU"):
# If GPU is available use Tensorflow gates
from qibo.tensorflow.gates import *
else:
# For CPU use custom operator gates
from qibo.tensorflow.cgates import *

from qibo.tensorflow.cgates import *
else:
raise NotImplementedError("Only Tensorflow backend is implemented.")
67 changes: 45 additions & 22 deletions src/qibo/tensorflow/custom_operators/cc/kernels/apply_gate.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,53 +48,76 @@ template <typename Device, typename T>
struct BaseOneQubitGateFunctor {
virtual void apply(T& state1, T& state2, const T* gate = NULL) const;

void operator()(const OpKernelContext* context, const Device& d,
T* state, //!< Total state vector.
int nqubits, //!< Total number of qubits in the state.
int target, //!< Target qubit id.
int ncontrols, //!< Number of qubits that the gate is controlled on.
const int32* controls, //!< List of control qubits ids sorted in decreasing order.
const T* gate = NULL //!< Gate matrix (used only by)
) const;
virtual void nocontrolwork(const Device& d, int numBlocks, int blockSize,
T* state, const T* gate, long tk, int m) const;

virtual void singlecontrolwork(const Device& d, int numBlocks, int blockSize,
T* state, const T* gate, long tk,
long k1, long k2, int m1, int m2) const;

virtual void multicontrolwork(const Device& d, int numBlocks, int blockSize,
T* state, const T* gate, long tk,
int m, int ncontrols,
const int* controls, int nqubits, int target) const;

void operator()(
const OpKernelContext* context, const Device& d,
T* state, //!< Total state vector.
int nqubits, //!< Total number of qubits in the state.
int target, //!< Target qubit id.
int ncontrols, //!< Number of qubits that the gate is controlled on.
const int32*
controls, //!< List of control qubits ids sorted in decreasing order.
const int32* tensor_controls, //!< List of control qubits ids sorted in
//!< decreasing order and stored on Device.
const T* gate = NULL //!< Gate matrix (used only by)
) const;
};

template <typename Device, typename T>
struct ApplyGateFunctor: BaseOneQubitGateFunctor<Device, T> {};
struct ApplyGateFunctor : BaseOneQubitGateFunctor<Device, T> {};

template <typename Device, typename T>
struct ApplyXFunctor: BaseOneQubitGateFunctor<Device, T> {};
struct ApplyXFunctor : BaseOneQubitGateFunctor<Device, T> {};

template <typename Device, typename T>
struct ApplyYFunctor: BaseOneQubitGateFunctor<Device, T> {};
struct ApplyYFunctor : BaseOneQubitGateFunctor<Device, T> {};

template <typename Device, typename T>
struct ApplyZFunctor: BaseOneQubitGateFunctor<Device, T> {};
struct ApplyZFunctor : BaseOneQubitGateFunctor<Device, T> {};

template <typename Device, typename T>
struct ApplyZPowFunctor: BaseOneQubitGateFunctor<Device, T> {};
struct ApplyZPowFunctor : BaseOneQubitGateFunctor<Device, T> {};

template <typename Device, typename T>
struct BaseTwoQubitGateFunctor {
virtual void apply(T* state, int64 i, int64 tk1, int64 tk2,
const T* gate = NULL) const;

virtual void nocontrolwork(const Device& d, int numBlocks, int blockSize,
T* state, const T* gate, long ctk1, long ctk2,
long tk1, long tk2, int m1, int m2) const;

virtual void multicontrolwork(const Device& d, int numBlocks, int blockSize,
T* state, const T* gate, long ctk1, long ctk2,
long tk1, long tk2, int m1, int m2,
int ncontrols, const int* controls, int nqubits,
int t1, int t2) const;

void operator()(const OpKernelContext* context, const Device& d, T* state,
int nqubits,
int target1,
int target2,
int ncontrols,
const int32* controls,
const T* gate = NULL);
int nqubits, int target1, int target2, int ncontrols,
const int32* controls, const int32* tensor_controls,
const T* gate = NULL) const;
};

template <typename Device, typename T>
struct ApplyTwoQubitGateFunctor: BaseTwoQubitGateFunctor<Device, T> {};
struct ApplyTwoQubitGateFunctor : BaseTwoQubitGateFunctor<Device, T> {};

template <typename Device, typename T>
struct ApplyFsimFunctor: BaseTwoQubitGateFunctor<Device, T> {};
struct ApplyFsimFunctor : BaseTwoQubitGateFunctor<Device, T> {};

template <typename Device, typename T>
struct ApplySwapFunctor: BaseTwoQubitGateFunctor<Device, T> {};
struct ApplySwapFunctor : BaseTwoQubitGateFunctor<Device, T> {};

} // namespace functor

Expand Down
Loading