CUDA работает!!
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
CXX = mpic++
|
||||
CXXFLAGS = -std=c++17 -O2 -Wall -Wextra -Wno-cast-function-type
|
||||
|
||||
NVCC = nvcc
|
||||
NVCCFLAGS = -O2 -Xcompiler -fPIC
|
||||
|
||||
SRC_DIR = src
|
||||
BUILD_DIR = build
|
||||
|
||||
@@ -9,7 +12,10 @@ OBJS = $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(SRCS))
|
||||
|
||||
TARGET = $(BUILD_DIR)/bitcoin_app
|
||||
|
||||
all: $(TARGET)
|
||||
PLUGIN_SRC = $(SRC_DIR)/gpu_plugin.cu
|
||||
PLUGIN = $(BUILD_DIR)/libgpu_compute.so
|
||||
|
||||
all: $(BUILD_DIR) $(PLUGIN) $(TARGET)
|
||||
|
||||
$(BUILD_DIR):
|
||||
mkdir -p $(BUILD_DIR)
|
||||
@@ -18,7 +24,10 @@ $(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp | $(BUILD_DIR)
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
$(TARGET): $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $^ -o $@
|
||||
$(CXX) $(CXXFLAGS) $^ -o $@ -ldl
|
||||
|
||||
$(PLUGIN): $(PLUGIN_SRC) | $(BUILD_DIR)
|
||||
$(NVCC) $(NVCCFLAGS) -shared $< -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
|
||||
@@ -4,4 +4,7 @@
|
||||
#SBATCH --ntasks=4
|
||||
#SBATCH --output=out.txt
|
||||
|
||||
mpirun -np 4 ./build/bitcoin_app
|
||||
# mpirun -np $SLURM_NTASKS ./build/bitcoin_app
|
||||
|
||||
cd /mnt/shared/supercomputers/bitcoin-project/build
|
||||
mpirun -np $SLURM_NTASKS ./bitcoin_app
|
||||
|
||||
12
bitcoin-project/src/gpu_loader.cpp
Normal file
12
bitcoin-project/src/gpu_loader.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "gpu_loader.hpp"
|
||||
#include <dlfcn.h>
|
||||
|
||||
gpu_is_available_fn load_gpu_is_available() {
|
||||
void* h = dlopen("./libgpu_compute.so", RTLD_NOW | RTLD_LOCAL);
|
||||
if (!h) return nullptr;
|
||||
|
||||
auto fn = (gpu_is_available_fn)dlsym(h, "gpu_is_available");
|
||||
if (!fn) return nullptr;
|
||||
|
||||
return fn;
|
||||
}
|
||||
4
bitcoin-project/src/gpu_loader.hpp
Normal file
4
bitcoin-project/src/gpu_loader.hpp
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
using gpu_is_available_fn = int (*)();
|
||||
|
||||
gpu_is_available_fn load_gpu_is_available();
|
||||
8
bitcoin-project/src/gpu_plugin.cu
Normal file
8
bitcoin-project/src/gpu_plugin.cu
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
extern "C" int gpu_is_available() {
|
||||
int n = 0;
|
||||
cudaError_t err = cudaGetDeviceCount(&n);
|
||||
if (err != cudaSuccess) return 0;
|
||||
return (n > 0) ? 1 : 0;
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "csv_loader.hpp"
|
||||
#include "utils.hpp"
|
||||
#include "record.hpp"
|
||||
#include "gpu_loader.hpp"
|
||||
|
||||
// Функция: отобрать записи для конкретного ранга
|
||||
std::vector<Record> select_records_for_rank(
|
||||
@@ -35,7 +36,7 @@ int main(int argc, char** argv) {
|
||||
if (rank == 0) {
|
||||
std::cout << "Rank 0 loading CSV..." << std::endl;
|
||||
|
||||
auto records = load_csv("data/data.csv");
|
||||
auto records = load_csv("/mnt/shared/supercomputers/bitcoin-project/data/data.csv");
|
||||
|
||||
auto days = group_by_day(records);
|
||||
auto parts = split_days(days, size);
|
||||
@@ -70,6 +71,16 @@ int main(int argc, char** argv) {
|
||||
std::cout << "Rank " << rank << " received "
|
||||
<< local_records.size() << " records" << std::endl;
|
||||
|
||||
|
||||
auto gpu_is_available = load_gpu_is_available();
|
||||
int have_gpu = 0;
|
||||
if (gpu_is_available) {
|
||||
std::cout << "Rank " << rank << " dll loaded" << std::endl;
|
||||
have_gpu = gpu_is_available();
|
||||
}
|
||||
|
||||
std::cout << "Rank " << rank << ": gpu_available=" << have_gpu << "\n";
|
||||
|
||||
MPI_Finalize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user