chapel icon indicating copy to clipboard operation
chapel copied to clipboard

[Bug]: Current `domain.shape` definition causing GPU issues (and is slower?)

Open Iainmon opened this issue 6 months ago • 5 comments

Summary of Problem

Description:

The current shape definition for domains https://github.com/chapel-lang/chapel/blob/8259035407d5ab40fd0956912e33e5e4d030b25a/modules/internal/ChapelDomain.chpl#L1480-L1489 is not ideal, and I suspect that it has been causing me problems when I refer to a domain's shape on GPU.

Could it be replaced with:

inline proc _domain.shape {
    var s: rank * int;
    const dms = dims();
    for param i in 0..<rank {
        s(i) = dms(i).sizeAs(int);
    }
    return s;
}

? Also, for trivial domains, the following is a faster alternative to orderToIndex:

        inline proc _domain.indexAt(n: int) where rank == 1 {
            return n;
        }
        inline proc _domain.indexAt(n: int) where rank > 1 {
            const shape_ = this.shape; // the one I mentioned. 
            var idx: rank * int;
            var order = n;
            var div = 1;
            for param i in 0..<rank do
                div *= shape_(i);
            for param i in 0..<rank {
                div /= shape_(i);
                idx(i) = order / div;
                order %= div;
            }
            return idx;
        }

Is this issue currently blocking your progress?

No.

Iainmon avatar Aug 01 '24 15:08 Iainmon