![]() |
cuLite v0.3.1
A lite CUDA C++ Interface
|
cuLite provides specialized classes for managing dense vectors on NVIDIA GPU devices. These classes are optimized for CUDA-accelerated linear algebra operations and support both real and complex numerical types.
The following classes are defined within the culite::dns namespace:
| cuLite Class | Numeric Type | Precision |
|---|---|---|
| culite::dns::RdVector | double | Double precision real |
| culite::dns::RfVector | float | Single precision real |
| culite::dns::CdVector | cuDoubleComplex | Double precision complex |
| culite::dns::CfVector | cuFloatComplex | Single precision complex |
You can instantiate dense vectors using several initialization strategies, ranging from empty containers to pre-allocated device memory.
Dense vectors can be declared as empty objects or with a predefined size to trigger immediate allocation on the GPU.
| Source Code | Console Output |
|---|---|
#include <iostream>
#include <culite/dense.hpp>
int main()
{
/*
* Double precision real empty vector
*/
std::cout << x.info("x");
/*
* Single precision real vector with size 3 (uninitialized values)
*/
culite::dns::RfVector y(3);
std::cout << y.info("y");
/*
* Allocate space for x (size 5, uninitialized values)
*/
x = culite::dns::RdVector(5);
std::cout << x.info("x");
return 0;
}
std::string info(const std::string &header="") const Get information about the device vector. XxVector< real_t > RdVector Double precision real device vector. Definition dense.hpp:31 XxVector< real4_t > RfVector Single precision real device vector. Definition dense.hpp:37 | ==================== x ====================
Datatype............. Real
Precision............ Double (64bit)
Size................. 0
Values............... 0
Owner................ No
===========================================
==================== y ====================
Datatype............. Real
Precision............ Single (32bit)
Size................. 3
Values............... 0x504c00000
Owner................ Yes
===========================================
==================== x ====================
Datatype............. Real
Precision............ Double (64bit)
Size................. 5
Values............... 0x504c00200
Owner................ Yes
===========================================
|
Creates a vector that acts as a "view" or wrapper around an existing C-style array. This avoids a deep copy of the data.
| Code | Output |
|---|---|
#include <iostream>
#include <cla3p/support.hpp>
#include <culite/support.hpp>
#include <culite/dense.hpp>
int main()
{
/*
* Allocate space for x & y on host
*/
cla3p::real_t *x_host = cla3p::i_calloc_t<cla3p::real_t>(5);
cla3p::real_t *y_host = cla3p::i_calloc_t<cla3p::real_t>(3);
for(cla3p::uint_t i = 0; i < 5; i++)
x_host[i] = i;
for(cla3p::uint_t i = 0; i < 3; i++)
y_host[i] = 3 - i;
/*
* Allocate space for x & y on device and copy data from host to device
*/
culite::real_t *x_device = culite::device_alloc_t<culite::real_t>(5);
culite::real_t *y_device = culite::device_alloc_t<culite::real_t>(3);
culite::memCopyH2D(5, x_host, x_device);
culite::memCopyH2D(3, y_host, y_device);
/*
* Assign pointer x in vector x but do not bind
* x simply hosts x, need to manually dealloc x
*/
culite::dns::RdVector x(5, x_device, false);
std::cout << x.info("x") << x;
/*
* Assign pointer y in vector y and bind
* y takes ownership of y, no free call for y is required
*/
culite::dns::RdVector y(3, y_device, true);
std::cout << y.info("y") << y;
/*
* Free x and exit
*/
cla3p::i_free(x_host);
cla3p::i_free(y_host);
culite::device_free(x_device);
// y_device is freed by y's destructor
return 0;
}
void i_free(void *ptr) T_Elem * i_calloc_t(std::size_t nmemb) double real_t T * device_alloc_t(std::size_t n) Allocates typed memory on the device. Definition imalloc.hpp:86 void memCopyH2D(std::size_t n, const T_Scalar *src, T_Scalar *dest) Copies a vector from host memory to device memory. Definition utils.hpp:71 | ==================== x ====================
Datatype............. Real
Precision............ Double (64bit)
Size................. 5
Values............... 0x504c00000
Owner................ No
===========================================
0
0 | 0.000000e+00
1 | 1.000000e+00
2 | 2.000000e+00
3 | 3.000000e+00
4 | 4.000000e+00
==================== y ====================
Datatype............. Real
Precision............ Double (64bit)
Size................. 3
Values............... 0x504c00200
Owner................ Yes
===========================================
0
0 | 3.000000e+00
1 | 2.000000e+00
2 | 1.000000e+00
|