Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 0 additions & 91 deletions libdevice/fallback-cassert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,99 +7,8 @@
//===----------------------------------------------------------------------===//

#include "atomic.hpp"
#include "include/assert-happened.hpp"
#include "wrapper.h"

#if defined(__SPIR__) || defined(__SPIRV__)

#define ASSERT_NONE 0
#define ASSERT_START 1
#define ASSERT_FINISH 2

// definition
SPIR_GLOBAL AssertHappened SPIR_AssertHappenedMem;

DEVICE_EXTERN_C void __devicelib_assert_read(void *_Dst) {
AssertHappened *Dst = (AssertHappened *)_Dst;
int Flag = atomicLoad(&SPIR_AssertHappenedMem.Flag);

if (ASSERT_NONE == Flag) {
Dst->Flag = Flag;
return;
}

if (Flag != ASSERT_FINISH)
while (ASSERT_START == atomicLoad(&SPIR_AssertHappenedMem.Flag))
;

*Dst = SPIR_AssertHappenedMem;
}

DEVICE_EXTERN_C void __devicelib_assert_fail(const char *expr, const char *file,
int32_t line, const char *func,
uint64_t gid0, uint64_t gid1,
uint64_t gid2, uint64_t lid0,
uint64_t lid1, uint64_t lid2) {
int Expected = ASSERT_NONE;
int Desired = ASSERT_START;

if (atomicCompareAndSet(&SPIR_AssertHappenedMem.Flag, Desired, Expected) ==
Expected) {
SPIR_AssertHappenedMem.Line = line;
SPIR_AssertHappenedMem.GID0 = gid0;
SPIR_AssertHappenedMem.GID1 = gid1;
SPIR_AssertHappenedMem.GID2 = gid2;
SPIR_AssertHappenedMem.LID0 = lid0;
SPIR_AssertHappenedMem.LID1 = lid1;
SPIR_AssertHappenedMem.LID2 = lid2;

int ExprLength = 0;
int FileLength = 0;
int FuncLength = 0;

if (expr)
for (const char *C = expr; *C != '\0'; ++C, ++ExprLength)
;
if (file)
for (const char *C = file; *C != '\0'; ++C, ++FileLength)
;
if (func)
for (const char *C = func; *C != '\0'; ++C, ++FuncLength)
;

int MaxExprIdx = sizeof(SPIR_AssertHappenedMem.Expr) - 1;
int MaxFileIdx = sizeof(SPIR_AssertHappenedMem.File) - 1;
int MaxFuncIdx = sizeof(SPIR_AssertHappenedMem.Func) - 1;

if (ExprLength < MaxExprIdx)
MaxExprIdx = ExprLength;
if (FileLength < MaxFileIdx)
MaxFileIdx = FileLength;
if (FuncLength < MaxFuncIdx)
MaxFuncIdx = FuncLength;

for (int Idx = 0; Idx < MaxExprIdx; ++Idx)
SPIR_AssertHappenedMem.Expr[Idx] = expr[Idx];
SPIR_AssertHappenedMem.Expr[MaxExprIdx] = '\0';

for (int Idx = 0; Idx < MaxFileIdx; ++Idx)
SPIR_AssertHappenedMem.File[Idx] = file[Idx];
SPIR_AssertHappenedMem.File[MaxFileIdx] = '\0';

for (int Idx = 0; Idx < MaxFuncIdx; ++Idx)
SPIR_AssertHappenedMem.Func[Idx] = func[Idx];
SPIR_AssertHappenedMem.Func[MaxFuncIdx] = '\0';

// Show we've done copying
atomicStore(&SPIR_AssertHappenedMem.Flag, ASSERT_FINISH);
}

// FIXME: call SPIR-V unreachable instead
// volatile int *die = (int *)0x0;
// *die = 0xdead;
}
#endif // __SPIR__ || __SPIRV__

#if defined(__NVPTX__) || defined(__AMDGCN__)

DEVICE_EXTERN_C void __assertfail(const char *__message, const char *__file,
Expand Down
48 changes: 0 additions & 48 deletions libdevice/include/assert-happened.hpp

This file was deleted.

Loading