forked from flagos-ai/FlagCX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch_kernel.cc
More file actions
56 lines (46 loc) · 1.45 KB
/
Copy pathlaunch_kernel.cc
File metadata and controls
56 lines (46 loc) · 1.45 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "launch_kernel.h"
#include "group.h"
#include <stdio.h>
flagcxLaunchFunc_t deviceAsyncLoad = NULL;
flagcxLaunchFunc_t deviceAsyncStore = NULL;
FLAGCX_PARAM(FuncMaxSpinCount, "FUNC_MAX_SPIN_COUNT", INT64_MAX);
static int64_t funcMaxSpinCount = flagcxParamFuncMaxSpinCount();
flagcxResult_t loadKernelSymbol(const char *path, const char *name,
flagcxLaunchFunc_t *fn) {
void *handle = flagcxOpenLib(
path, RTLD_LAZY, [](const char *p, int err, const char *msg) {
fprintf(stderr, "dlopen failed: %s\n", dlerror());
});
if (!handle)
return flagcxSystemError;
void *sym = dlsym(handle, name);
if (!sym) {
fprintf(stderr, "dlsym failed: %s\n", dlerror());
return flagcxSystemError;
}
*fn = (flagcxLaunchFunc_t)sym;
return flagcxSuccess;
}
void cpuAsyncStore(void *args) {
bool *volatile value = (bool *)args;
__atomic_store_n(value, 1, __ATOMIC_RELAXED);
}
void cpuAsyncLoad(void *args) {
bool *volatile value = (bool *)args;
while (!__atomic_load_n(value, __ATOMIC_RELAXED)) {
}
}
void cpuAsyncLoadWithMaxSpinCount(void *args) {
bool *volatile value = (bool *)args;
int64_t spinCount = 0;
while (!__atomic_load_n(value, __ATOMIC_RELAXED) &&
spinCount < funcMaxSpinCount) {
spinCount++;
}
}
void cpuAsyncKernel(void *args) {
flagcxHostSemaphore *semaphore = (flagcxHostSemaphore *)args;
semaphore->signalStart();
semaphore->wait();
semaphore->signalEnd();
}