Skip to content

Commit 752c8e4

Browse files
authored
just cpu things (#27)
1 parent 3e7997c commit 752c8e4

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

README.noformat

+5
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ Key _MKN_GPU_THREADED_STREAM_LAUNCHER_WAIT_MS_MAX_
4141
Type uint
4242
Default 100
4343
Description Max wait time in milliseconds for polling active jobs for completion when no job is finished.
44+
45+
Key MKN_CPU_DO_NOT_DEFINE_DIM3
46+
Type bool
47+
Default false
48+
Description if true, skips defining dim3 struct which is usually provided by gpu headers

inc/mkn/gpu.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3535

3636
namespace mkn::gpu {
3737

38-
__device__ uint32_t idx() {
38+
__device__ uint32_t inline idx() {
3939
#if MKN_GPU_ROCM
4040
return mkn::gpu::hip::idx();
4141

inc/mkn/gpu/cpu.hpp

+26-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4141
#include "mkn/gpu/cli.hpp"
4242
#include "mkn/gpu/def.hpp"
4343

44+
#include <algorithm>
4445
#include <cassert>
4546
#include <cstring>
4647

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

6465
// we need to exclude these for CPU only operations
66+
#define __shared__
6567
#define __device__
6668
#define __host__
6769
#define __global__
70+
#define __syncthreads(...)
6871

6972
#if defined(MKN_GPU_FN_PER_NS) && MKN_GPU_FN_PER_NS
7073
#define MKN_GPU_NS mkn::gpu::cpu
7174
#else
7275
#define MKN_GPU_NS mkn::gpu
7376
#endif // MKN_GPU_FN_PER_NS
7477

75-
namespace MKN_GPU_NS {
78+
#if !defined(MKN_CPU_DO_NOT_DEFINE_DIM3)
79+
#define MKN_CPU_DO_NOT_DEFINE_DIM3 0
80+
#endif
7681

82+
#if !defined(dim3) and !MKN_CPU_DO_NOT_DEFINE_DIM3
7783
struct dim3 {
7884
dim3() {}
7985
dim3(std::size_t x) : x{x} {}
@@ -83,6 +89,14 @@ struct dim3 {
8389
std::size_t x = 1, y = 1, z = 1;
8490
};
8591

92+
dim3 static inline threadIdx, blockIdx;
93+
94+
#endif // MKN_CPU_DO_NOT_DEFINE_DIM3
95+
96+
//
97+
98+
namespace MKN_GPU_NS {
99+
86100
void inline setLimitMallocHeapSize(std::size_t const& /*bytes*/) {} /*noop*/
87101

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

273+
template <typename Container, typename T>
274+
void fill(Container& c, size_t const size, T const val) {
275+
std::fill(c.begin(), c.begin() + size, val);
276+
}
277+
278+
template <typename Container, typename T>
279+
void fill(Container& c, T const val) {
280+
fill(c, c.size(), val);
281+
}
282+
259283
void inline prinfo(std::size_t /*dev*/ = 0) { KOUT(NON) << "Psuedo GPU in use"; }
260284

261285
} // namespace MKN_GPU_NS
262286

263287
namespace mkn::gpu::cpu {
264288

265289
template <typename SIZE = std::uint32_t /*max 4294967296*/>
266-
SIZE idx() {
290+
SIZE inline idx() {
267291
return MKN_GPU_NS::detail::idx;
268292
}
269293

inc/mkn/gpu/defines.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#endif
3333

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

0 commit comments

Comments
 (0)