using 3rd party STM library with icc

using 3rd party STM library with icc

Portrait de aleksandar

I am trying to use my STM library with Intel's STM compiler, but am encountering problems with free and malloc functions.

I implemented all functions in the ABI specification and created a static library. When I try to link some benchmark application with my STM library the linker complains about missingfree._$TXN and malloc._$TXN. Linking with the library that is shipped with the compiler works fine. Doing a "nm libitm.a" shows that these two functions are defined in Intel STM library. I thought that the compiler should invoke _ITM_free and _ITM_malloc when it encounters free and malloc calls inside transactions, but this seems not to happen. Any ideas about how to solve this? Aleksandar
10 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.
Portrait de Ravi Narayanaswamy (Intel)
Quoting - I am trying to use my STM library with Intel's STM compiler, but am encountering problems with free and malloc functions. I implemented all functions in the ABI specification and created a static library. When I try to link some benchmark application with my STM library the linker complains about missingfree._$TXN and malloc._$TXN. Linking with the library that is shipped with the compiler works fine. Doing a "nm libitm.a" shows that these two functions are defined in Intel STM library. I thought that the compiler should invoke _ITM_free and _ITM_malloc when it encounters free and malloc calls inside transactions, but this seems not to happen. Any ideas about how to solve this? Aleksandar

Yes the compiler invokes _ITM_free and _ITM_malloc when it encouters free and malloc calls inside transcations, these functions are provided as part of libitm.a. You will need to implement your own STM malloc and free using the API defined in Intel TM ABI 1_0_1 section: 5.17.1 User commit and undo functions

Portrait de aleksandar
Quoting - Ravi Narayanaswamy (Intel)

Yes the compiler invokes _ITM_free and _ITM_malloc when it encouters free and malloc calls inside transcations, these functions are provided as part of libitm.a. You will need to implement your own STM malloc and free using the API defined in Intel TM ABI 1_0_1 section: 5.17.1 User commit and undo functions

Thanks for the answer. I am not sure that I got it though. Why is the linker complaining about missingfree._$TXN and malloc._$TXN if calls to free and malloc get replaced by calls to _ITM_free and _ITM_malloc?
Aleksandar
Portrait de Ravi Narayanaswamy (Intel)
Quoting -

Thanks for the answer. I am not sure that I got it though. Why is the linker complaining about missingfree._$TXN and malloc._$TXN if calls to free and malloc get replaced by calls to _ITM_free and _ITM_malloc?
Aleksandar

The compiler recognizes malloc and free and actually generates call to a malloc and free wrapper function _mall0c.$WrapTXN. Seen the Language Extensions and User's Guide section 3.9 on tm_wrapping annotation. The compiler generate calls to malloc._$TXN and free._$TXN only if you have disabled optimization (/Od) or disable intrinsic function recognization (/Oi-) and annotated malloc and free with attribute tm_callable.

Portrait de aleksandar
Quoting - Ravi Narayanaswamy (Intel)

The compiler recognizes malloc and free and actually generates call to a malloc and free wrapper function _mall0c.$WrapTXN. Seen the Language Extensions and User's Guide section 3.9 on tm_wrapping annotation. The compiler generate calls to malloc._$TXN and free._$TXN only if you have disabled optimization (/Od) or disable intrinsic function recognization (/Oi-) and annotated malloc and free with attribute tm_callable.

Here is a very simple test case:

#include int main() { void *data; __tm_atomic { data = malloc(10); } }
I call the file test_icc.c and compile it with: icpc -O3 -Qtm_enabled test_icc.c -o test_icc -L$(PATH_TO_MY_LIB) -litm and get: test_icc.c:(.text+0x43): undefined reference to `malloc._$TXN'. I am running a Linux version of the compiler. icc -v just says "Prototype Edition 3.0". Aleksandar
Portrait de Ravi Narayanaswamy (Intel)
Quoting -

Here is a very simple test case:

#include int main() { void *data; __tm_atomic { data = malloc(10); } }
I call the file test_icc.c and compile it with: icpc -O3 -Qtm_enabled test_icc.c -o test_icc -L$(PATH_TO_MY_LIB) -litm and get: test_icc.c:(.text+0x43): undefined reference to `malloc._$TXN'. I am running a Linux version of the compiler. icc -v just says "Prototype Edition 3.0". Aleksandar

Yes for direct calls to malloc the compiler replaces with calls to malloc.$TXN which is TM safe malloc. The safety in malloc.$TXN is provided by remembering the object allocated, the nesting scope andregistering the action to be taken on undo and on commit. Similiarly free.$TXN is TM safe by releasing the object at the right nesting level

Portrait de aleksandar
Quoting - Ravi Narayanaswamy (Intel)

Yes for direct calls to malloc the compiler replaces with calls to malloc.$TXN which is TM safe malloc. The safety in malloc.$TXN is provided by remembering the object allocated, the nesting scope andregistering the action to be taken on undo and on commit. Similiarly free.$TXN is TM safe by releasing the object at the right nesting level

Thank you for the clarification.


How do I create malloc.$TXN and free.$TXN in my library? I guess that I should create tm_wrapper functions for them? What are _ITM_malloc and _ITM_free used for then?
Portrait de Ravi Narayanaswamy (Intel)
Quoting - aleksandar

Thank you for the clarification.


How do I create malloc.$TXN and free.$TXN in my library? I guess that I should create tm_wrapper functions for them? What are _ITM_malloc and _ITM_free used for then?

Yes you should create tm_wrapper for malloc and free.
Ignore ITM_malloc and ITM_free they are equivalent to malloc.$TXN and free.$TXN

Portrait de stylian

Hello, I have a similar problem. I don't know if it is possible to use this thread or I have to create a new one.

I am using Prototype 4.0 and I obtain "undefined reference to `malloc._$TXN'" and "undefined reference to `free._$TXN'" when I try to link to a static library that I have created with the ABI functions. I have tried to create t_wrappers for malloc and free as you have told but the problem continues. I use Linux and I have tried the following options:

__attribute__(tm_wrapping(malloc._$TXN)) void *malloc(size_t); __attribute__(tm_wrapping(malloc)) void *malloc._$TXN(size_t); __declspec(tm_wrapping(malloc._$TXN)) void *malloc(size_t);
__declspec(tm_wrapping(malloc)) void *malloc._$TXN(size_t);

Portrait de patrick.marlier

Hello,
You can have a look how we handle that in TinySTM for Intel STM Compiler. Extracted from source: void *malloc_txn(size_t size) __asm__("malloc._$TXN"); void *malloc_txn(size_t size){ return stm_malloc(size); } Hope it helps even if the reply is quite late.

Connectez-vous pour laisser un commentaire.