Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/src/runtime/rx_cm_sort.h # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / src / runtime / rx_cm_sort.h` 60 lines · 2498 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 #ifndef RX_CM_SORT_H 3 #define RX_CM_SORT_H 4 #include "cudapp_native.h" 5 #include 6 #include 7 #ifndef CUDAPP_MIGRATION_PENDING_C_CM_SORT 8 #define CUDAPP_MIGRATION_PENDING_C_CM_SORT 0 9 #endif 10 #if CUDAPP_MIGRATION_PENDING_C_CM_SORT 11 /* Total comparator: resolves formerly unspecified NaN and signed-zero ties. */ 12 static int rx_cm_cmp(const void *pa, const void *pb) { 13 double a, b; uint64_t ab, bb; 14 memcpy(&a,pa,8); memcpy(&b,pb,8); memcpy(&ab,pa,8); memcpy(&bb,pb,8); 15 if (a != a) { if (b == b) return 1; } 16 else { if (b != b) return -1; if (a < b) return -1; if (a > b) return 1; } 17 return (ab > bb) - (ab < bb); 18 } 19 #endif 20 static inline int rx_cm_sort(double *values, size_t n) { 21 #if CUDAPP_MIGRATION_PENDING_C_CM_SORT 22 qsort(values,n,sizeof *values,rx_cm_cmp); return 0; 23 #else 24 if (n < 2) return 0; 25 if (n > SIZE_MAX / sizeof *values) return -1; 26 uint64_t left[256]={0}, right[256]={0}, out[256]={0}, meta[4]={0}, done; 27 for (size_t i=0;i256 || meta[2]>na || meta[3]>nb || done!=meta[2]+meta[3]) { free(scratch);return -1; } 47 memcpy(dst+k,out,(size_t)done*sizeof *values); 48 a+=(size_t)meta[2];b+=(size_t)meta[3];k+=(size_t)done; 49 } 50 start=end; 51 } 52 double *swap=src;src=dst;dst=swap; 53 if(width>n/2)break; 54 width*=2; 55 } 56 if(src!=values)memcpy(values,src,n*sizeof *values); 57 free(scratch);return 0; 58 #endif 59 } 60 #endif