GCC cilkplus and zca

GCC cilkplus and zca


I'm trying to develop some Pin tools that track Cilk-related events using libzca, and I'm having some difficulties getting the tool to work with GCC.

I've written a tutorial Pin tool that counts instructions, spawns, and a custom annotation I've added using __notify_intrinsic().  The code for this Pin tool is given below.

#include <assert.h>
#include <cstdio>
#include <cstdlib>
#include <pin.H>
#include <zca_table.h>
/** Data structures
static UINT64 work = 0;
static UINT64 spawn_count = 0;
static UINT64 custom_annotation = 0;
/** Callback functions
static void detach_callback()
static void count_work(UINT32 n)
 work += n;
static void custom_annotation_callback()
/** Instrumentation functions
// A defn{trace} is a single-entry multiple-exit sequence of
// instructions. Pin evaluates a program as a sequence of traces,
// subdividing each trace into basic blocks determined by control flow
// during execution.
// This function is called to instrument traces.
static void instrument_trace(TRACE trace, void *)
 for (BBL bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl = BBL_Next(bbl))
 BBL_InsertCall(bbl, IPOINT_BEFORE, (AFUNPTR)count_work, IARG_UINT32, BBL_NumIns(bbl), IARG_END);
// This function is called when program terminates. This function
// cleans up outstanding data structures and outputs results.
static void instrument_fini(INT32 code, void *)
 printf("Work: %llunSpawns: %llunCustom Annotation: %llun",
 work, spawn_count, custom_annotation);
/** Main
// Table of metadata and callbacks based on zero-cost annotations (ZCA).
static ZCA::zca_table zca;
int main(int argc, char *argv[])
 // Initialize Pin to use the symbol table
 if (PIN_Init(argc, argv)) {
 // If we can't parse the arguments, die.
 fprintf(stderr, "error parsing arguments.n");
 return -1;
// Register instrumentation function with Pin.
 TRACE_AddInstrumentFunction(instrument_trace, 0);
// Register function to be called when application exits
 PIN_AddFiniFunction(instrument_fini, 0);
// Register callback functions for Cilk events.
// Register callback functions for custom events
// Start the program, never returns
 return 0;

I'm compiling this Pin tool using the Makefile shipped with cilkprof modified to compile my Pin tool instead of cilkprof.  I've been testing this tool on a standard parallel fib example with __notify_intrinsic() statements added inside of main():

int main(int argc, char* argv[])
 uint64_t n, x;
if (argc != 2) {
 fprintf(stderr, "Usage: %s <n>n", argv[0]);
n = atol(argv[1]);
__notify_intrinsic((void*)"top_fib_enter", 0);
 x = fib(n);
 __notify_intrinsic((void*)"top_fib_exit", 0);
printf("%lun", x);
return 0;

While I've managed to get this tool to work using ICC, I haven't been able to get it to work when I compile fib using the cilkplus branch of GCC.  In particular, while the tool seems to correctly count spawns and my custom annotation when fib is compiled with ICC, it always produces a spawn count of 0 and a custom annotation count of 0 when fib is compiled with GCC.  (On an unrelated note, to compile fib with GCC, I have to remove the (void*) casts inside of the __notify_intrinsic() calls to placate the compiler.)

I was wondering if there is anything special I need to do when compiling either fib or the Pin tool to get things working under GCC.  Do I need to compile to tool using GCC instead of ICC?  Are there special compiler switches I need to specify to GCC to get the annotations inserted?

Thank you for your help,


4 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

Tao, what are the errors you get? I've tried unsuccessfully to do stuff with libpin.a using GCC, though one of my students had some success while using ICC. The problem I remember is that libpin.a was not compiled statically with -fPIC, but (it seems) it was! GCC did not happen to see this and I could never ld (link). I asked a question on this forum a while back, and while Barry could reproduce the error, it seems it was a problem for the people over at pintools. I haven't heard back from them.

This was in both 32 and 64 bits. There seems to be something funky going over with GCC that doesn't happen with ICC. I'm interested in this, can I help you reproduce the error?

This has been fixed by build 195 of the libzca toolkit, which is now available at http://cilkplus.org/download#contributions . The bug was due to GCC creating a metadata table per function instead of merging all of the compatible tables like ICC does.  Cilkview does not use libzca, and this bug has been fixed previously in Cilkview and Cilkscreen.

    - Barry

RE: leoferres

I passed your issue to the PIN developers, but I haven't hread back from them.  I'll ping them and see if they have a solution.

    - Barry

Lascia un commento

Eseguire l'accesso per aggiungere un commento. Non siete membri? Iscriviti oggi