Skip to content

Commit

Permalink
implemented the very basics of the first three classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
olivas committed Apr 16, 2024
1 parent 0dbaeaa commit 04ac6b1
Show file tree
Hide file tree
Showing 12 changed files with 483 additions and 41 deletions.
4 changes: 3 additions & 1 deletion cmake_files/library.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@


add_library(cudapp SHARED
src/device.cu
src/device_properties.cu
src/device_manager.cu
../include/cudapp/cuda_device_prop.hpp
)
set_property(TARGET cudapp PROPERTY CUDA_ARCHITECTURES OFF)

4 changes: 4 additions & 0 deletions cmake_files/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ add_test(test_device bin/test_device)
add_executable(test_device_manager tests/test_device_manager.cpp)
target_link_libraries(test_device_manager cudapp)
add_test(test_device_manager bin/test_device_manager)

add_executable(test_device_properties tests/test_device_properties.cpp)
target_link_libraries(test_device_properties cudapp)
add_test(test_device_properties bin/test_device_properties)
89 changes: 89 additions & 0 deletions include/cudapp/cuda_device_prop.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// Created by olivas on 4/15/24.
//

#ifndef CUDAPP_CUDA_DEVICE_PROP_HPP
#define CUDAPP_CUDA_DEVICE_PROP_HPP

#include <array>
#include <string>

struct cuda_device_prop {
std::string name;
std::string uuid; // 16 byte unique identifier
size_t totalGlobalMem;
size_t sharedMemPerBlock;
unsigned regsPerBlock;
unsigned warpSize;
size_t memPitch;
unsigned maxThreadsPerBlock;
std::array<unsigned, 3> maxThreadsDim;
std::array<unsigned, 3> maxGridSize;
unsigned clockRate;
size_t totalConstMem;
unsigned major;
unsigned minor;
size_t textureAlignment;
size_t texturePitchAlignment;
unsigned deviceOverlap;
unsigned multiProcessorCount;
unsigned kernelExecTimeoutEnabled;
unsigned integrated;
unsigned canMapHostMemory;
unsigned computeMode;
unsigned maxTexture1D;
unsigned maxTexture1DMipmap;
unsigned maxTexture1DLinear;
std::array<unsigned, 2> maxTexture2D;
std::array<unsigned, 2> maxTexture2DMipmap;
std::array<unsigned, 3> maxTexture2DLinear;
std::array<unsigned, 2> maxTexture2DGather;
std::array<unsigned, 3> maxTexture3D;
std::array<unsigned, 3> maxTexture3DAlt;
unsigned maxTextureCubemap;
std::array<unsigned, 2> maxTexture1DLayered;
std::array<unsigned, 3> maxTexture2DLayered;
std::array<unsigned, 2> maxTextureCubemapLayered;
unsigned maxSurface1D;
std::array<unsigned, 2> maxSurface2D;
std::array<unsigned, 3> maxSurface3D;
std::array<unsigned, 2> maxSurface1DLayered;
std::array<unsigned, 3> maxSurface2DLayered;
unsigned maxSurfaceCubemap;
std::array<unsigned, 2> maxSurfaceCubemapLayered;
size_t surfaceAlignment;
unsigned concurrentKernels;
unsigned ECCEnabled;
unsigned pciBusID;
unsigned pciDeviceID;
unsigned pciDomainID;
unsigned tccDriver;
unsigned asyncEngineCount;
unsigned unifiedAddressing;
unsigned memoryClockRate;
unsigned memoryBusWidth;
unsigned l2CacheSize;
unsigned persistingL2CacheMaxSize;
unsigned maxThreadsPerMultiProcessor;
unsigned streamPrioritiesSupported;
unsigned globalL1CacheSupported;
unsigned localL1CacheSupported;
size_t sharedMemPerMultiprocessor;
unsigned regsPerMultiprocessor;
unsigned managedMemory;
unsigned isMultiGpuBoard;
unsigned multiGpuBoardGroupID;
unsigned singleToDoublePrecisionPerfRatio;
unsigned pageableMemoryAccess;
unsigned concurrentManagedAccess;
unsigned computePreemptionSupported;
unsigned canUseHostPointerForRegisteredMem;
unsigned cooperativeLaunch;
unsigned cooperativeMultiDeviceLaunch;
unsigned pageableMemoryAccessUsesHostPageTables;
unsigned directManagedMemAccessFromHost;
unsigned accessPolicyMaxWindowSize;
};


#endif //CUDAPP_CUDA_DEVICE_PROP_HPP
26 changes: 14 additions & 12 deletions include/cudapp/device.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#pragma once

class Device{
public:
Device(int device_number);
~Device();
namespace cudapp{
class Device{
public:
Device(int device_number);
~Device();

int multi_processor_count() const { return multi_processor_count_; }
size_t total_global_mem() const { return total_global_mem_; }

private:
int device_number_;
int multi_processor_count_;
size_t total_global_mem_;
};
int multi_processor_count() const { return multi_processor_count_; }
size_t total_global_mem() const { return total_global_mem_; }

private:
int device_number_;
int multi_processor_count_;
size_t total_global_mem_;
};
}
31 changes: 18 additions & 13 deletions include/cudapp/device_manager.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
#pragma once

class DeviceManager{
public:
DeviceManager();
~DeviceManager();

int multi_processor_count() const { return multi_processor_count_; }
size_t total_global_mem() const { return total_global_mem_; }

private:
int device_number_;
int multi_processor_count_;
size_t total_global_mem_;
};
#include <optional>

namespace cudapp{
class DeviceManager {
public:
DeviceManager();

~DeviceManager();

[[nodiscard("this method's job is to return a value.")]]
std::optional<unsigned> device_count() const;

[[nodiscard("this method's job is to return a value.")]]
std::optional<unsigned> current_device() const;

};

}
28 changes: 28 additions & 0 deletions include/cudapp/device_properties.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <optional>

#include <cudapp/cuda_device_prop.hpp>

namespace cudapp{
class DeviceProperties {
public:

DeviceProperties(unsigned device_number);

~DeviceProperties();

void change_device_number(unsigned device_number);

cuda_device_prop device_properties;

void pretty_print();

private:

unsigned device_number_;

void set_device_properties(const unsigned device_number);
};
}

4 changes: 2 additions & 2 deletions src/device.cu
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <cudapp/device.hpp>
#include <cudapp/check_error.cuh>

Device::Device(int device_number):
cudapp::Device::Device(int device_number):
device_number_(device_number)
{
CHECK_ERROR(cudaSetDeviceFlags(cudaDeviceBlockingSync));
Expand All @@ -14,7 +14,7 @@ Device::Device(int device_number):
multi_processor_count_ = device_properties.multiProcessorCount;
}

Device::~Device()
cudapp::Device::~Device()
{
CHECK_ERROR(cudaDeviceReset());
}
Expand Down
27 changes: 15 additions & 12 deletions src/device_manager.cu
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#include <cudapp/device_manager.hpp>
#include <cudapp/check_error.cuh>

DeviceManager::DeviceManager()
{
CHECK_ERROR(cudaSetDeviceFlags(cudaDeviceBlockingSync));
CHECK_ERROR(cudaSetDevice(device_number_));
std::cerr<<"device_number_ = "<<device_number_<<std::endl;
using std::optional;

cudaDeviceProp device_properties;
CHECK_ERROR(cudaGetDeviceProperties(&device_properties, device_number_));
total_global_mem_ = device_properties.totalGlobalMem;
multi_processor_count_ = device_properties.multiProcessorCount;
cudapp::DeviceManager::DeviceManager() {}

optional<unsigned>
cudapp::DeviceManager::device_count() const {
int device_count{0};
CHECK_ERROR(cudaGetDeviceCount(&device_count));
return static_cast<unsigned>(device_count);
}

DeviceManager::~DeviceManager()
{
CHECK_ERROR(cudaDeviceReset());
optional<unsigned>
cudapp::DeviceManager::current_device() const {
int device{0};
CHECK_ERROR(cudaGetDevice(&device));
return static_cast<unsigned>(device);
}

cudapp::DeviceManager::~DeviceManager() {}

Loading

0 comments on commit 04ac6b1

Please sign in to comment.