Open ianmccul opened 5 days ago
We should clean up the code base...
I also propose to put only public API header files in cytnx/include and keep the private headers next to the cpp files. In this way we have a clear separation of user level API and internal functions.
A small number of files that are installed as part of the public API include some conditional code hidden behind
This should not appear in header files in the user API in
include/
.Network.hpp
This conditionally adds variables with typecutensornetNetworkDescriptor_t
andcutensornetContractionOptimizerInfo_t
to theNetwork_base
class. This means it will produce an ABI incompatibility ifUNI_GPU
andUNI_CUQUANTUM
in user code is different to how it was configured when the library was installed. Better option would be to put this behind an opaque type, say,NetworkImplementation
(forward declared as an incomplete type in the header) and replace the cuda types withstd::unique_ptr<NetworkImplementation>
. (Note there are some minor technicalities with having astd::unique_ptr
to an incomplete type, but it does work, and was designed to be allowed.) 2.utils/cucomplex_arithmetic.hpp
This is included fromutils/utils.hpp
. It declares a bunch of overloads for equality comparison and operator* betweencuComplex
and builtin types. I have no idea why it exists -- user code using cytnx normally wouldn't ever need to deal withcuFloatComplex
andcuDoubleComplex
directly.utils/complex_arithmetic.hpp
complex<double>
/complex<float>
and builtin types (double, float, int etc). Most of them already exist in namespacestd
anyway, but a few of them do not (which I guess is the purpose of the header...). Since they are declared innamespace cytnx
, user code typically would not ever find them (unlessusing namespace cytnx
, and then it is asking for trouble with two clashing overloads). Some of them are a bit strange, eg what doescytnx_complex64 operator/(const cytnx_bool &rn, const cytnx_complex64 &ln)
do?! [edit: actually I think all of them exist innamespace std
, via implicit conversion from builtin types to complex] But it also includes a copy-and-paste of the cuComplexoperator==
declarations that also appear inutils/cucomplex_arithmetic.hpp
(but not theoperator*
overloads...)cytnx_error.hpp
This looks like a lot of it was copy-pasted from https://github.com/NVIDIA/cuda-samples/blob/master/Common/helper_cuda.h . None of the CUDA-related functions are referred to anywhere else in the include files, so it looks like these could simply be removed from the public API. (also_cudaGetErrorEnum()
could be replaced by the CUDA functioncuGetErrorString()
. But I suggest simply importinghelper_cuda.h
from the CUDA samples into thesrc/
directory and using it as-is.