19 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
20 defined(__DragonFly__)
38 #ifdef MLIR_CRUNNERUTILS_DEFINE_FUNCTIONS
42 void stdSort(uint64_t n, V *p) {
52 extern "C" void printI64(int64_t i) { fprintf(stdout,
"%" PRId64, i); }
53 extern "C" void printU64(uint64_t u) { fprintf(stdout,
"%" PRIu64, u); }
55 if (std::isnan(f) && std::signbit(f)) {
56 fprintf(stdout,
"-nan");
58 fprintf(stdout,
"%g", f);
62 if (std::isnan(d) && std::signbit(d)) {
63 fprintf(stdout,
"-nan");
65 fprintf(stdout,
"%lg", d);
68 extern "C" void printString(
char const *s) { fputs(s, stdout); }
69 extern "C" void printOpen() { fputs(
"( ", stdout); }
70 extern "C" void printClose() { fputs(
" )", stdout); }
71 extern "C" void printComma() { fputs(
", ", stdout); }
79 int64_t rank = src.rank;
83 for (
int rankp = 0; rankp < rank; ++rankp)
84 if (src.sizes[rankp] == 0)
87 char *srcPtr = src.data + src.offset * elemSize;
88 char *dstPtr = dst.data + dst.offset * elemSize;
91 memcpy(dstPtr, srcPtr, elemSize);
95 int64_t *indices =
static_cast<int64_t *
>(alloca(
sizeof(int64_t) * rank));
96 int64_t *srcStrides =
static_cast<int64_t *
>(alloca(
sizeof(int64_t) * rank));
97 int64_t *dstStrides =
static_cast<int64_t *
>(alloca(
sizeof(int64_t) * rank));
100 for (
int rankp = 0; rankp < rank; ++rankp) {
102 srcStrides[rankp] = src.strides[rankp] * elemSize;
103 dstStrides[rankp] = dst.strides[rankp] * elemSize;
106 int64_t readIndex = 0, writeIndex = 0;
109 memcpy(dstPtr + writeIndex, srcPtr + readIndex, elemSize);
111 for (int64_t axis = rank - 1; axis >= 0; --axis) {
113 auto newIndex = ++indices[axis];
114 readIndex += srcStrides[axis];
115 writeIndex += dstStrides[axis];
117 if (src.sizes[axis] != newIndex)
125 readIndex -= src.sizes[axis] * srcStrides[axis];
126 writeIndex -= dst.sizes[axis] * dstStrides[axis];
133 fprintf(stderr,
"%lf GFLOPS\n", flops / 1.0E9);
140 int stat = gettimeofday(&tp,
nullptr);
142 fprintf(stderr,
"Error returning time from gettimeofday: %d\n", stat);
143 return (tp.tv_sec + tp.tv_usec * 1.0e-6);
145 fprintf(stderr,
"Timing utility not implemented on Windows\n");
150 extern "C" void *mlirAlloc(uint64_t size) {
return malloc(size); }
152 extern "C" void *mlirAlignedAlloc(uint64_t alignment, uint64_t size) {
154 return _aligned_malloc(size, alignment);
155 #elif defined(__APPLE__)
158 void *result =
nullptr;
159 (void)::posix_memalign(&result, alignment, size);
162 return aligned_alloc(alignment, size);
166 extern "C" void mlirFree(
void *ptr) { free(ptr); }
168 extern "C" void mlirAlignedFree(
void *ptr) {
176 extern "C" void *
rtsrand(uint64_t s) {
178 return new std::mt19937(s);
181 extern "C" uint64_t
rtrand(
void *g, uint64_t m) {
182 std::mt19937 *
generator =
static_cast<std::mt19937 *
>(g);
183 std::uniform_int_distribution<uint64_t> distrib(0, m);
187 extern "C" void rtdrand(
void *g) {
188 std::mt19937 *
generator =
static_cast<std::mt19937 *
>(g);
196 std::mt19937 *
generator =
static_cast<std::mt19937 *
>(g);
197 uint64_t s = mref->
sizes[0];
199 std::iota(data, data + s, 0);
200 std::shuffle(data, data + s, *
generator);
203 #define IMPL_STDSORT(VNAME, V) \
204 extern "C" void _mlir_ciface_stdSort##VNAME(uint64_t n, \
205 StridedMemRefType<V, 1> *vref) { \
207 assert(vref->strides[0] == 1); \
208 V *values = vref->data + vref->offset; \
209 stdSort(n, values); \
211 IMPL_STDSORT(I64, int64_t)
212 IMPL_STDSORT(F64,
double)
213 IMPL_STDSORT(F32,
float)
MLIR_CRUNNERUTILS_EXPORT void printI64(int64_t i)
MLIR_CRUNNERUTILS_EXPORT void printF32(float f)
MLIR_CRUNNERUTILS_EXPORT void printString(char const *s)
MLIR_CRUNNERUTILS_EXPORT void printU64(uint64_t u)
MLIR_CRUNNERUTILS_EXPORT void memrefCopy(int64_t elemSize, ::UnrankedMemRefType< char > *src, ::UnrankedMemRefType< char > *dst)
MLIR_CRUNNERUTILS_EXPORT void printNewline()
MLIR_CRUNNERUTILS_EXPORT void * rtsrand(uint64_t s)
MLIR_CRUNNERUTILS_EXPORT void printOpen()
MLIR_CRUNNERUTILS_EXPORT void printFlops(double flops)
MLIR_CRUNNERUTILS_EXPORT void rtdrand(void *g)
MLIR_CRUNNERUTILS_EXPORT double rtclock()
MLIR_CRUNNERUTILS_EXPORT void printClose()
MLIR_CRUNNERUTILS_EXPORT uint64_t rtrand(void *g, uint64_t m)
MLIR_CRUNNERUTILS_EXPORT void printF64(double d)
MLIR_CRUNNERUTILS_EXPORT void _mlir_ciface_shuffle(StridedMemRefType< uint64_t, 1 > *mref, void *g)
MLIR_CRUNNERUTILS_EXPORT void printComma()
static const mlir::GenInfo * generator
#define MLIR_MSAN_MEMORY_IS_INITIALIZED(p, s)
StridedMemRef descriptor type with static rank.