Skip to content

Commit

Permalink
add PDL::Trans methods to aid debug-dumping
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Jan 21, 2024
1 parent a424155 commit 08da40b
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 2 deletions.
36 changes: 36 additions & 0 deletions Basic/Core/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,42 @@ Returns a list of ndarrays that are inputs to this trans.
Returns a list of ndarrays that are outputs to this trans (specified as
C<[o]>, C<[oca]>, C<[io]>, or C<[t]> in C<Pars>).
=item address
The memory address of the struct.
=item name
The function name from the vtable.
=item flags
List of strings of flags set for this trans.
=item flags_vtable
List of strings of flags set for this trans's vtable.
=item vaffine
Whether the trans is affine.
=item offs
Affine-only: the offset into the parent's data.
=item incs
Affine-only: the dimincs for each of the child's dims.
=item ind_sizes
The size of each named dim.
=item inc_sizes
The size of the inc for each use of a named dim.
=back
=head2 trans_children
Expand Down
87 changes: 87 additions & 0 deletions Basic/Core/Core.xs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@
PUSHs(sv); \
}

#define PDL_FLAG_COMMA(f) f,
#define PDL_FLAG_STRCOMMA(f) #f,
#define PDL_FLAG_DUMP(macro, flagvar) \
int flagval[] = { \
macro(PDL_FLAG_COMMA) \
0 \
}; \
char *flagchar[] = { \
macro(PDL_FLAG_STRCOMMA) \
NULL \
}; \
int i, f = flagvar; \
for (i=0; flagval[i]!=0; i++) \
if (f & flagval[i]) \
XPUSHs(sv_2mortal(newSVpv(flagchar[i], 0)));

#define setflag(reg,flagval,val) (val?(reg |= flagval):(reg &= ~flagval))

Core PDL; /* Struct holding pointers to shared C routines */
Expand Down Expand Up @@ -230,6 +246,77 @@ children(trans)
PPCODE:
TRANS_PDLS(vtable->nparents, vtable->npdls)

IV
address(self)
pdl_trans *self;
CODE:
RETVAL = PTR2IV(self);
OUTPUT:
RETVAL

char *
name(self)
pdl_trans *self;
CODE:
if (!self->vtable) barf("%p has NULL vtable", self);
RETVAL = self->vtable->name;
OUTPUT:
RETVAL

void
flags(x)
pdl_trans *x
PPCODE:
PDL_FLAG_DUMP(PDL_LIST_FLAGS_PDLTRANS, x->flags)

void
flags_vtable(x)
pdl_trans *x
PPCODE:
if (!x->vtable) barf("%p has NULL vtable", x);
PDL_FLAG_DUMP(PDL_LIST_FLAGS_PDLVTABLE, x->vtable->flags)

int
vaffine(x)
pdl_trans *x
CODE:
RETVAL= !!(x->flags & PDL_ITRANS_ISAFFINE);
OUTPUT:
RETVAL

IV
offs(self)
pdl_trans *self;
CODE:
RETVAL = PTR2IV(self->offs);
OUTPUT:
RETVAL

void
incs(x)
pdl_trans *x;
PPCODE:
if (!(x->flags & PDL_ITRANS_ISAFFINE)) barf("incs called on non-vaffine trans %p", x);
PDL_Indx i, max = x->incs ? x->pdls[1]->ndims : 0;
EXTEND(sp, max);
for(i=0; i<max; i++) mPUSHi(x->incs[i]);

void
ind_sizes(x)
pdl_trans *x;
PPCODE:
PDL_Indx i, max = x->vtable->ninds;
EXTEND(sp, max);
for(i=0; i<max; i++) mPUSHi(x->ind_sizes[i]);

void
inc_sizes(x)
pdl_trans *x;
PPCODE:
PDL_Indx i, max = x->vtable->nind_ids;
EXTEND(sp, max);
for(i=0; i<max; i++) mPUSHi(x->inc_sizes[i]);

MODULE = PDL::Core PACKAGE = PDL::Core

IV
Expand Down
4 changes: 2 additions & 2 deletions Basic/Core/pdlutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ void pdl_dump_trans_fixspace (pdl_trans *it, int nspac) {
PDL_Indx i;
SET_SPACE(spaces, nspac);
printf("%sDUMPTRANS %p (%s)\n",spaces,(void*)it,it->vtable->name);
pdl_dump_flags_fixspace(it->flags,nspac+3,PDL_FLAGS_TRANS);
pdl_dump_flags_fixspace(it->flags,nspac+3, PDL_FLAGS_TRANS);
printf("%s vtable flags ",spaces);
pdl_dump_flags_fixspace(it->vtable->flags,nspac+3,PDL_FLAGS_VTABLE);
if(it->flags & PDL_ITRANS_ISAFFINE) {
Expand All @@ -429,7 +429,7 @@ void pdl_dump_trans_fixspace (pdl_trans *it, int nspac) {
printf("%s%p",(i?" ":""),(void*)(it->pdls[i]));
printf(") OUTPUTS: (");
for(;i<it->vtable->npdls; i++)
printf("%s%p",(i?" ":""),(void*)(it->pdls[i]));
printf("%s%p",(i>it->vtable->nparents?" ":""),(void*)(it->pdls[i]));
printf(")\n");
}

Expand Down
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- switch FFT code to use heap, not VLA (#436) - thanks @HaraldJoerg for report
- add methods PDL::Trans::{address,name,flags,flags_vtable,vaffine,offs,incs,ind_sizes,inc_sizes}

2.084 2023-05-21
- reduce size of PDL_KLUDGE_COPY_X macro to <4096 in line with C standard, to fix for older clang on many BSD
Expand Down

0 comments on commit 08da40b

Please sign in to comment.