[IR] Add memory instrumentation mode
Add an IR instrumentation to check buffer overflows. Usecase For backend specific kernel implementations there might cases when even if a kernel correctly computes the output it might write more than it should thus overflowing the buffer is allocated. These kind of situations are hard to debug. Implementation Add a mechanism in IR to:
- allocate an extra header and extra footer for each buffer (the MemoryAllocator should be instructed so)
- in order to no violate the alignment each buffer will be allocated an extra of ALIGN bytes for header and an extra ALIGN bytes for footer where ALIGN is the default alignment used by the MemoryAllocator
- we generate code for the AllocActivation instruction to write at runtime a stamp in the buffer header/footer
- we generate code for the DeallocActivation instruction to check at runtime the header/footer stamps are intact, otherwise we return an error code using the error handling in LLVMIRGen provided by "createCheckedCall" As a bonus we can enable this feature for all our unit tests.
@mciprian13 Were you thinking of this just being used for debugging, or a real feature? Does ASAN not work to check this?
@jfix71 This is intended to be a kernel debugging feature. For example what if for a custom backend (e.g. an accelerator) we have a buggy convolution which although correctly computes the output it writes some extra data in the output buffer thus overflowing it (in the activations memory section this might overwrite some other data). This is a real usecase and I actually lost a lot of time debugging what happened within a larger model. So this is a debugging feature mainly for e.g. libjit kernels.