Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ylxiao/dev #218

Merged
merged 4 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions tapa-lib/tapa/host/mmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ class mmap {
uint64_t size_;
};

template <typename T>
class immap : public mmap<T> {
public:
// Inherit all constructors from mmap
using mmap<T>::mmap;
};

template <typename T>
class ommap : public mmap<T> {
public:
// Inherit all constructors from mmap
using mmap<T>::mmap;
};

/// Defines a view of a piece of consecutive memory with asynchronous random
/// accesses.
template <typename T>
Expand Down Expand Up @@ -475,6 +489,57 @@ TAPA_DEFINE_MMAP(read_only);
TAPA_DEFINE_MMAP(write_only);
TAPA_DEFINE_MMAP(read_write);
#undef TAPA_DEFINE_MMAP

// Host-only immap types that must have correct size.
#define TAPA_DEFINE_IMMAP(tag) \
template <typename T> \
class tag##_immap : public immap<T> { \
tag##_immap(T* ptr) : immap<T>(ptr) {} \
\
public: \
using immap<T>::immap; \
tag##_immap(const immap<T>& base) : immap<T>(base) {} \
\
template <uint64_t N> \
tag##_immap<vec_t<T, N>> vectorized() const { \
return immap<T>::template vectorized<N>(); \
} \
template <typename U> \
tag##_immap<U> reinterpret() const { \
return immap<T>::template reinterpret<U>(); \
} \
}
TAPA_DEFINE_IMMAP(placeholder);
TAPA_DEFINE_IMMAP(read_only);
TAPA_DEFINE_IMMAP(write_only);
TAPA_DEFINE_IMMAP(read_write);
#undef TAPA_DEFINE_IMMAP

// Host-only ommap types that must have correct size.
#define TAPA_DEFINE_OMMAP(tag) \
template <typename T> \
class tag##_ommap : public ommap<T> { \
tag##_ommap(T* ptr) : ommap<T>(ptr) {} \
\
public: \
using ommap<T>::ommap; \
tag##_ommap(const ommap<T>& base) : ommap<T>(base) {} \
\
template <uint64_t N> \
tag##_ommap<vec_t<T, N>> vectorized() const { \
return ommap<T>::template vectorized<N>(); \
} \
template <typename U> \
tag##_ommap<U> reinterpret() const { \
return ommap<T>::template reinterpret<U>(); \
} \
}
TAPA_DEFINE_OMMAP(placeholder);
TAPA_DEFINE_OMMAP(read_only);
TAPA_DEFINE_OMMAP(write_only);
TAPA_DEFINE_OMMAP(read_write);
#undef TAPA_DEFINE_OMMAP

#define TAPA_DEFINE_MMAPS(tag) \
template <typename T, uint64_t S> \
class tag##_mmaps : public mmaps<T, S> { \
Expand Down Expand Up @@ -605,4 +670,19 @@ struct accessor<mmaps<T, S>, mmaps<T, S>> {

} // namespace tapa

// Generalized window_readincr for AIE
template <typename T>
T window_readincr(tapa::immap<const T>& mem) {
T res = *mem;
mem++;
return res;
}

// Generalized window_writeincr for AIE
template <typename T>
void window_writeincr(tapa::ommap<T>& mem, const T& val) {
*mem = val;
mem++;
}

#endif // TAPA_HOST_MMAP_H_
27 changes: 27 additions & 0 deletions tapa-lib/tapa/stub/mmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ class mmap {
mmap<U> reinterpret() const;
};

template <typename T>
class immap : public mmap<T> {
public:
// Inherit all constructors from mmap
using mmap<T>::mmap;
};

template <typename T>
class ommap : public mmap<T> {
public:
// Inherit all constructors from mmap
using mmap<T>::mmap;
};

template <typename T>
struct async_mmap : public mmap<T> {
public:
Expand Down Expand Up @@ -86,3 +100,16 @@ class hmap : public mmap<T> {
};

} // namespace tapa

template <typename Mem>
auto window_readincr(Mem& mem) -> decltype(*mem) {
auto value = *mem; // Read the current value
++mem; // Increment to the next location
return value; // Return the read value
}

template <typename Mem, typename T>
void window_writeincr(Mem& mem, const T& value) {
*mem = value; // Write the value at the current memory position
++mem; // Increment to the next memory position
}
Loading
Loading