Skip to content

Commit

Permalink
add typecheck for basic MPI types
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderlinne committed Jun 16, 2021
1 parent 15b4efc commit b8295b9
Showing 1 changed file with 78 additions and 4 deletions.
82 changes: 78 additions & 4 deletions lib/mpi_interceptor/InterceptorFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#include <sys/resource.h>
#include <sys/time.h>

int ta_check_buffer(const char* mpi_name, const void* called_from, const void* buf, int mpi_count, int const_adr);
int ta_mpi_type_to_type_id(MPI_Datatype mpi_type);
int ta_check_buffer(const char* mpi_name, const void* called_from, const void* buf, MPI_Datatype mpi_type,
int mpi_count, int const_adr);
void ta_print_loc(const void* call_adr);

typedef struct CallCounter {
Expand All @@ -39,12 +41,12 @@ static MPICounter mcounter = {0, 0, 0};

void ta_check_send(const char* name, const void* called_from, const void* sendbuf, int count, MPI_Datatype dtype) {
++counter.send;
ta_check_buffer(name, called_from, sendbuf, count, 1);
ta_check_buffer(name, called_from, sendbuf, dtype, count, 1);
}

void ta_check_recv(const char* name, const void* called_from, void* recvbuf, int count, MPI_Datatype dtype) {
++counter.recv;
ta_check_buffer(name, called_from, recvbuf, count, 0);
ta_check_buffer(name, called_from, recvbuf, dtype, count, 0);
}

void ta_check_send_and_recv(const char* name, const void* called_from, const void* sendbuf, int sendcount,
Expand Down Expand Up @@ -80,7 +82,68 @@ const char* ta_get_error_message(typeart_status status) {
}
}

int ta_check_buffer(const char* mpi_name, const void* called_from, const void* buf, int mpi_count, int const_adr) {
int ta_mpi_map_int_type(size_t int_sizeof) {
if (int_sizeof == 1) {
return TA_INT8;
} else if (int_sizeof == 2) {
return TA_INT16;
} else if (int_sizeof == 4) {
return TA_INT32;
} else if (int_sizeof == 8) {
return TA_INT64;
} else {
fprintf(stderr, "[Error] Unsupperted integer width %lu!", int_sizeof);
return TA_UNKNOWN_TYPE;
}
}

// Given an MPI type, returns the corresponding TypeArt type.
// Note: this function cannot distinguish between TA_FP128 und TA_PPC_TP128,
// therefore TA_FP128 is always returned in case of an 16 byte floating point
// MPI type. This should be considered by the caller for performing typechecks.
int ta_mpi_type_to_type_id(MPI_Datatype mpi_type) {
if (mpi_type == MPI_CHAR) {
fprintf(stderr, "[Error] MPI_CHAR is currently unsupported!");
} else if (mpi_type == MPI_UNSIGNED_CHAR) {
fprintf(stderr, "[Error] MPI_UNSIGNED_CHAR is currently unsupported!");
} else if (mpi_type == MPI_SIGNED_CHAR) {
fprintf(stderr, "[Error] MPI_SIGNED_CHAR is currently unsupported!");
} else if (mpi_type == MPI_SHORT) {
return ta_mpi_map_int_type(sizeof(short));
} else if (mpi_type == MPI_UNSIGNED_SHORT) {
fprintf(stderr, "[Error] Unsigned integers are currently not supported!");
} else if (mpi_type == MPI_INT) {
return ta_mpi_map_int_type(sizeof(int));
} else if (mpi_type == MPI_UNSIGNED) {
fprintf(stderr, "[Error] Unsigned integers are currently not supported!");
} else if (mpi_type == MPI_LONG) {
return ta_mpi_map_int_type(sizeof(long int));
} else if (mpi_type == MPI_UNSIGNED_LONG) {
fprintf(stderr, "[Error] Unsigned integers are currently not supported!");
} else if (mpi_type == MPI_LONG_LONG_INT) {
return ta_mpi_map_int_type(sizeof(long long int));
} else if (mpi_type == MPI_FLOAT) {
return TA_FLOAT;
} else if (mpi_type == MPI_DOUBLE) {
return TA_DOUBLE;
} else if (mpi_type == MPI_LONG_DOUBLE) {
if (sizeof(long double) == sizeof(double)) {
return TA_DOUBLE;
} else if (sizeof(long double) == 10) {
return TA_X86_FP80;
} else if (sizeof(long double) == 16) {
return TA_FP128;
} else {
fprintf(stderr, "[Error] long double has unexpected size %zu!", sizeof(long double));
}
} else {
fprintf(stderr, "[Error] Unsupported MPI datatype found!");
}
return TA_UNKNOWN_TYPE;
}

int ta_check_buffer(const char* mpi_name, const void* called_from, const void* buf, MPI_Datatype mpi_type,
int mpi_count, int const_adr) {
if (mpi_count <= 0) {
++mcounter.null_count;
return 1;
Expand All @@ -103,6 +166,17 @@ int ta_check_buffer(const char* mpi_name, const void* called_from, const void* b
ta_print_loc(called_from);
return 0;
}
const char* type_name = typeart_get_type_name(typeId);
const int mpi_type_id = ta_mpi_type_to_type_id(mpi_type);
const char* mpi_type_name = typeart_get_type_name(mpi_type_id);
printf("R[%d][Info][%d] %s: buffer %p has type %s, MPI type is %s\n", rank, const_adr, mpi_name, buf, type_name,
mpi_type_name);
if (typeId != mpi_type_id && !(typeId == TA_PPC_FP128 && mpi_type_id == TA_FP128)) {
printf("R[%d][Error][%d] %s: buffer %p at loc %p has type %s while the MPI type is %s\n", rank, const_adr, mpi_name,
buf, called_from, type_name, mpi_type_name);
ta_print_loc(called_from);
return -1;
}
// if (mpi_count > count) {
// TODO: Count check not really sensible without taking the MPI type into account
// printf("R[%d][Error][%d] Call '%s' buffer %p too small\n", rank, const_adr, mpi_name, buf);
Expand Down

0 comments on commit b8295b9

Please sign in to comment.