-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcuda_main.cpp
More file actions
39 lines (32 loc) · 963 Bytes
/
cuda_main.cpp
File metadata and controls
39 lines (32 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <dlfcn.h>
int main() {
void* handle = dlopen("./libcuda_add.so", RTLD_LAZY);
if (!handle) {
std::cerr << "Cannot open library: " << dlerror() << '\n';
return 1;
}
typedef void (*addVectors_t)(int*, const int*, const int*, int);
addVectors_t addVectors = (addVectors_t)dlsym(handle, "addVectors");
const char* dlsym_error = dlerror();
if (dlsym_error) {
std::cerr << "Cannot load symbol 'addVectors': " << dlsym_error << '\n';
dlclose(handle);
return 1;
}
const int size = 10;
int a[size] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int b[size] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
int c[size] = {0};
addVectors(c, a, b, size);
for (int i = 0; i < size; i++) {
std::cout << c[i] << " ";
}
std::cout << std::endl;
dlclose(handle);
return 0;
}
/*
chatgpt作ホスト側メインプログラム
g++ -o main main.cpp -ldl
*/