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
5 changes: 5 additions & 0 deletions README.noformat
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ Key _MKN_GPU_THREADED_STREAM_LAUNCHER_WAIT_MS_MAX_
Type uint
Default 100
Description Max wait time in milliseconds for polling active jobs for completion when no job is finished.

Key MKN_CPU_DO_NOT_DEFINE_DIM3
Type bool
Default false
Description if true, skips defining dim3 struct which is usually provided by gpu headers
2 changes: 1 addition & 1 deletion inc/mkn/gpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

namespace mkn::gpu {

__device__ uint32_t idx() {
__device__ uint32_t inline idx() {
#if MKN_GPU_ROCM
return mkn::gpu::hip::idx();

Expand Down
28 changes: 26 additions & 2 deletions inc/mkn/gpu/cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "mkn/gpu/cli.hpp"
#include "mkn/gpu/def.hpp"

#include <algorithm>
#include <cassert>
#include <cstring>

Expand All @@ -62,18 +63,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endif

// we need to exclude these for CPU only operations
#define __shared__
#define __device__
#define __host__
#define __global__
#define __syncthreads(...)

#if defined(MKN_GPU_FN_PER_NS) && MKN_GPU_FN_PER_NS
#define MKN_GPU_NS mkn::gpu::cpu
#else
#define MKN_GPU_NS mkn::gpu
#endif // MKN_GPU_FN_PER_NS

namespace MKN_GPU_NS {
#if !defined(MKN_CPU_DO_NOT_DEFINE_DIM3)
#define MKN_CPU_DO_NOT_DEFINE_DIM3 0
#endif

#if !defined(dim3) and !MKN_CPU_DO_NOT_DEFINE_DIM3
struct dim3 {
dim3() {}
dim3(std::size_t x) : x{x} {}
Expand All @@ -83,6 +89,14 @@ struct dim3 {
std::size_t x = 1, y = 1, z = 1;
};

dim3 static inline threadIdx, blockIdx;

#endif // MKN_CPU_DO_NOT_DEFINE_DIM3

//

namespace MKN_GPU_NS {

void inline setLimitMallocHeapSize(std::size_t const& /*bytes*/) {} /*noop*/

void inline setDevice(std::size_t const& /*dev*/) {} /*noop*/
Expand Down Expand Up @@ -256,14 +270,24 @@ struct GLauncher : public Launcher {
std::size_t count;
};

template <typename Container, typename T>
void fill(Container& c, size_t const size, T const val) {
std::fill(c.begin(), c.begin() + size, val);
}

template <typename Container, typename T>
void fill(Container& c, T const val) {
fill(c, c.size(), val);
}

void inline prinfo(std::size_t /*dev*/ = 0) { KOUT(NON) << "Psuedo GPU in use"; }

} // namespace MKN_GPU_NS

namespace mkn::gpu::cpu {

template <typename SIZE = std::uint32_t /*max 4294967296*/>
SIZE idx() {
SIZE inline idx() {
return MKN_GPU_NS::detail::idx;
}

Expand Down
1 change: 0 additions & 1 deletion inc/mkn/gpu/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#endif

#if MKN_GPU_CUDA == 0 && MKN_GPU_ROCM == 0 && !defined(MKN_GPU_CPU)
#pragma message("mkn.gpu error: No accelerator found, defaulting to CPU IMP")
#define MKN_GPU_CPU 1
#endif

Expand Down