Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

fix(cuda): stop parked issuers before teardown

ZacharyZcR510cfa59c72b
diff --git a/c/qwen36_tier.c b/c/qwen36_tier.c
index dffa5ed8..7d6bcc4c 100644
--- a/c/qwen36_tier.c
+++ b/c/qwen36_tier.c
@@ -1089,6 +1089,7 @@ uint32_t qt_issue(int layer,const int *eids,int K,const float *x){
* six entries still queued). No group is open here, so the wait cannot
* meet a swap parked on issue_open. */
if(G_upload_sync) while(G.inflight>0 && !G.th_stop) wait_take_locked();
+ if(G.th_stop){ pthread_mutex_unlock(&G.mx); return 0; }
if(layer==0) qt_lfru_tick_locked();
G.issue_open=1;
for(int k=0;k<K;k++){
diff --git a/c/tests/test_qwen36_tier_shutdown.c b/c/tests/test_qwen36_tier_shutdown.c
index 16a3370c..c9797193 100644
--- a/c/tests/test_qwen36_tier_shutdown.c
+++ b/c/tests/test_qwen36_tier_shutdown.c
@@ -67,6 +67,15 @@ static int wait_for_resident(int layer, int eid, int want, int max_polls) {
return 0;
}
+static uint32_t stopped_issue_mask;
+static void *waiting_issue(void *arg) {
+ (void)arg;
+ int eid=0;
+ float x[64]={0};
+ stopped_issue_mask=qt_issue(0,&eid,1,x);
+ return NULL;
+}
+
int main(void) {
enum { D = 64 };
setenv("COLI_CUDA", "1", 1);
@@ -139,6 +148,37 @@ int main(void) {
check(G.uploads == 1 && fake_uploads == 3,
"shutdown_abandons_the_swap_without_uploading_the_incoming_expert");
+ /* A synchronous issue parked behind an upload must not submit new work
+ * after shutdown wakes it. Hold the inflight predicate explicitly so the
+ * stop transition is deterministic, independent of upload timing. */
+ if(!qt_init(1,2,D,32,2,1,0,1)) return 1;
+ qt_note(0,0,g4[0],u4[0],d4[0],sc[0],sc[0]+32,sc[0]+64);
+ qt_fill_wait();
+ G_upload_sync=1;
+ pthread_mutex_lock(&G.mx);
+ G.inflight=1;
+ pthread_mutex_unlock(&G.mx);
+ pthread_t issuer;
+ if(pthread_create(&issuer,NULL,waiting_issue,NULL)) return 1;
+ int waiting=0;
+ for(int i=0;i<500;i++){
+ pthread_mutex_lock(&G.mx);
+ waiting=G.waiters>0;
+ pthread_mutex_unlock(&G.mx);
+ if(waiting) break;
+ struct timespec ts={0,2000000}; nanosleep(&ts,NULL);
+ }
+ check(waiting,"issuer parked before stop");
+ pthread_mutex_lock(&G.mx);
+ G.th_stop=1;
+ pthread_cond_broadcast(&G.cv_take);
+ pthread_cond_signal(&G.cv);
+ pthread_mutex_unlock(&G.mx);
+ pthread_join(issuer,NULL);
+ check(stopped_issue_mask==0,"stopped issuer must return CPU fallback mask");
+ check(!G.issue_open && !G.is_cnt[0],"stopped issuer must not open a GPU group");
+ qt_shutdown();
+
if (fails) { printf("test_qwen36_tier_shutdown: %d fallimenti\n", fails); return 1; }
printf("test_qwen36_tier_shutdown: ok\n");
return 0;