Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:

- name: test
run: |
curl -Lo mkn https://github.com/mkn/mkn/releases/download/latest/mkn_nix
curl -fL --retry 3 --retry-delay 2 -o mkn https://github.com/mkn/mkn/releases/download/latest/mkn_nix
chmod +x mkn
KLOG=3 ./mkn clean build run -dtKOgp cpu -a "-std=c++20" test -W 9
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bin
.mkn
*.cui
.clangd
*.clangd
14 changes: 13 additions & 1 deletion inc/mkn/gpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef _MKN_GPU_HPP_
#define _MKN_GPU_HPP_

#include "mkn/gpu/defines.hpp"
#include "mkn/gpu/def.hpp"

#if MKN_GPU_ROCM
#include "mkn/gpu/rocm.hpp"
#endif

#if MKN_GPU_CUDA
#include "mkn/gpu/cuda.hpp"
#endif

#if MKN_GPU_CPU
#include "mkn/gpu/cpu.hpp"
#endif

namespace mkn::gpu {

Expand Down
24 changes: 24 additions & 0 deletions inc/mkn/gpu/any/cls.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef _MKN_GPU_ANY_CLS_HPP_
#define _MKN_GPU_ANY_CLS_HPP_

#include "mkn/kul/env.hpp"
#include "mkn/kul/string.hpp"

namespace mkn::gpu {

template <typename Device>
struct Cli {
constexpr static inline char const* MKN_GPU_BX_THREADS = "MKN_GPU_BX_THREADS";

auto bx_threads() const {
if (kul::env::EXISTS(MKN_GPU_BX_THREADS))
return kul::String::INT32(kul::env::GET(MKN_GPU_BX_THREADS));
return dev.maxThreadsPerBlock;
}

Device const& dev;
};

} /* namespace mkn::gpu */

#endif /*_MKN_GPU_ANY_CLS_HPP_*/
Comment thread
PhilipDeegan marked this conversation as resolved.
4 changes: 4 additions & 0 deletions inc/mkn/gpu/any/def.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef _MKN_GPU_ANY_DEF_HPP_
#define _MKN_GPU_ANY_DEF_HPP_

#endif /*_MKN_GPU_ANY_DEF_HPP_*/
File renamed without changes.
9 changes: 9 additions & 0 deletions inc/mkn/gpu/any/inc/devfunc.ipp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

template <bool sync = true, typename T>
void __device__ fill_warp_size(T* const t, std::size_t const size, T const val) {
std::size_t chunk = 0;
auto const each = size / warpSize;
for (; chunk < each; ++chunk) t[chunk * warpSize + threadIdx.x] = val;
if (threadIdx.x < size - (warpSize * each)) t[chunk * warpSize + threadIdx.x] = val;
if constexpr (sync) __syncthreads();
}
Comment thread
PhilipDeegan marked this conversation as resolved.
8 changes: 4 additions & 4 deletions inc/mkn/gpu/device.hpp → inc/mkn/gpu/any/inc/device.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ struct DeviceMem {
}

void send(T const* t, std::size_t _size = 1, std::size_t start = 0) {
MKN_GPU_NS::send(p, t, _size, start);
MKN_GPU_NS::send(p + start, t, _size);
}

template <typename C, std::enable_if_t<mkn::kul::is_span_like_v<C>, bool> = 0>
void send(C const& c, std::size_t start = 0) {
send(c.data(), c.size(), start);
send(c.data() + start, c.size());
}

void fill_n(T t, std::size_t _size, std::size_t start = 0) {
Expand Down Expand Up @@ -128,14 +128,14 @@ struct AsioDeviceMem {

void send(Stream& stream, T* t, std::size_t _size = 1, std::size_t start = 0) {
assert(p != nullptr);
MKN_GPU_NS::send_async(p, t, stream, _size, start);
MKN_GPU_NS::send_async(p + start, t + start, stream(), _size);
}

template <typename Span>
void take(Stream& stream, Span& span, std::size_t start) {
assert(p != nullptr);
assert(span.size() + start <= s);
MKN_GPU_NS::take_async(p, span, stream, start);
MKN_GPU_NS::take_async(p + start, span.data(), stream(), span.size());
}

auto& size() const { return s; }
Expand Down
File renamed without changes.
Empty file added inc/mkn/gpu/any/inc/traits.ipp
Empty file.
55 changes: 0 additions & 55 deletions inc/mkn/gpu/cli.hpp

This file was deleted.

30 changes: 14 additions & 16 deletions inc/mkn/gpu/cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,34 +193,32 @@ void send(void* p, void* t, Size size = 1) {
}

template <typename T, typename Size>
void send(T* p, T const* t, Size size = 1, Size start = 0) {
void send(T* p, T const* t, Size size = 1) {
KLOG(TRC);
MKN_GPU_ASSERT(std::memcpy(p + start, t, size * sizeof(T)));
MKN_GPU_ASSERT(std::memcpy(p, t, size * sizeof(T)));
}

template <typename T, typename Size>
void take(T* p, T* t, Size size = 1, Size start = 0) {
void send_async(T* p, T const* t, auto& /*stream*/, Size size = 1) {
KLOG(TRC);
MKN_GPU_ASSERT(std::memcpy(t, p + start, size * sizeof(T)));
send(p, t, size);
}

template <typename T, typename Size>
void send_async(T* p, T const* t, Stream& /*stream*/, Size size = 1, Size start = 0) {
void take(T const* p, T* t, Size size = 1) {
KLOG(TRC);
send(p, t, size, start);
MKN_GPU_ASSERT(std::memcpy(t, p, size * sizeof(T)));
}

template <typename T, typename Span>
void take_async(T* p, Span& span, Stream& /*stream*/, std::size_t start) {
static_assert(mkn::kul::is_span_like_v<Span>);
template <typename T, typename Size>
void take_async(T const* p, T* t, auto& /*stream*/, Size size = 1) {
KLOG(TRC);
take(p, span.data(), span.size(), start);
take(p, t, size);
}

void inline sync() {}

#include "mkn/gpu/alloc.hpp"
#include "mkn/gpu/device.hpp"
#include "mkn/gpu/any/inc/alloc.ipp"
#include "mkn/gpu/any/inc/device.ipp"

namespace detail {
static thread_local std::size_t idx = 0;
Expand Down Expand Up @@ -281,8 +279,8 @@ void fill(Container& c, T const val) {
}

template <typename T>
void zero(T* const t, std::size_t const size) {
std::fill(t, t + size, 0);
void fill_warp_size(T* const t, std::size_t const size, T const val) {
std::fill(t, t + size, val);
}

void inline prinfo(std::size_t /*dev*/ = 0) { KOUT(NON) << "Psuedo GPU in use"; }
Expand Down Expand Up @@ -310,7 +308,7 @@ static void global_d_kernel(F& f, Args... args) {
f(args...);
}

#include "launchers.hpp"
#include "mkn/gpu/any/inc/launchers.ipp"

} /* namespace MKN_GPU_NS */

Expand Down
4 changes: 4 additions & 0 deletions inc/mkn/gpu/cpu/api.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef _MKN_GPU_CPU_API_HPP_
#define _MKN_GPU_CPU_API_HPP_

#endif /*_MKN_GPU_CPU_API_HPP_*/
4 changes: 4 additions & 0 deletions inc/mkn/gpu/cpu/cls.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef _MKN_GPU_CPU_CLS_HPP_
#define _MKN_GPU_CPU_CLS_HPP_

#endif /*_MKN_GPU_CPU_CLS_HPP_*/
4 changes: 4 additions & 0 deletions inc/mkn/gpu/cpu/def.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef _MKN_GPU_CPU_DEF_HPP_
#define _MKN_GPU_CPU_DEF_HPP_

#endif /*_MKN_GPU_CPU_DEF_HPP_*/
Comment thread
PhilipDeegan marked this conversation as resolved.
Loading