SkillAgentSearch skills...

CudaMem

A library to mimic the behavior of smart pointers from STL to CUDA.

Install / Use

/learn @AhmedARadwan/CudaMem
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

CudaMem

CudaMem is a C++ library that provides smart pointers for managing memory on CUDA-enabled devices. It includes implementations of both unique and shared pointers, allowing you to efficiently allocate, deallocate, and transfer data between the host and device memory without using cudaMalloc or cudaFree.

Prerequisities

Tested with:

  • CUDA 11.1
  • GCC 7.5

Installation

To install CudaSmartPointers, follow these steps:

  1. Clone the repository:

    git clone https://github.com/ahmedaradwan/CudaMem.git
    
  2. Navigate to the project directory:

    cd CudaMem
    
  3. Create a build directory:

    mkdir build
    cd build
    
  4. Configure the project with CMake:

    cmake ..
    
  5. Build the project:

    make
    
  6. Optionally, install the library:

    sudo make install
    

Example Usage

Here's a simple example demonstrating how to use the unique pointer from the CudaSmartPointers library:

#include "CudaMem.h"
#include <memory>
#include <vector>
#include <iostream>
#include <random>

int main(){

    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<long> dis(1, 1000000);

    std::vector<long> host_indexes;
    const int num_elements = 100;

    for (int i = 0; i < num_elements; ++i) {
        host_indexes.push_back(dis(gen));
    }

    CudaMem::shared_ptr<long> device_indexes;

    device_indexes.copyToDevice(host_indexes);

    std::vector<long> host_indexes_2(device_indexes.getSize());
    device_indexes.copyToHost(host_indexes_2);


    for (const auto& i : host_indexes_2){
        std::cout << "Vector element: " << i << std::endl;
    }

    return 0;
}

References

ecuda CudaSharedPtr

View on GitHub
GitHub Stars9
CategoryDevelopment
Updated10mo ago
Forks0

Languages

C++

Security Score

77/100

Audited on May 23, 2025

No findings