Skip to content

Commit

Permalink
Final cleaning of tinyocl.h.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbikker committed Nov 18, 2024
1 parent 2eb739a commit a40718f
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tiny_ocl.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,51 +48,51 @@ inline size_t make_multiple_64( size_t x ) { return (x + 63) & ~0x3f; }
#ifdef _MSC_VER // Visual Studio / C11
#define ALIGNED( x ) __declspec( align( x ) )
namespace tinyocl {
inline void* default_aligned_malloc( size_t size, void* = nullptr )
inline void* malloc64( size_t size, void* = nullptr )
{
return size == 0 ? 0 : _aligned_malloc( make_multiple_64( size ), 64 );
}
inline void default_aligned_free( void* ptr, void* = nullptr ) { _aligned_free( ptr ); }
inline void free64( void* ptr, void* = nullptr ) { _aligned_free( ptr ); }
}
#elif defined(__EMSCRIPTEN__) // EMSCRIPTEN - needs to be before gcc and clang to avoid misdetection
#define ALIGNED( x ) __attribute__( ( aligned( x ) ) )
#if defined(__wasm_simd128__) || defined(__wasm_relaxed_simd__)
// https://emscripten.org/docs/porting/simd.html
#include <xmmintrin.h>
namespace tinyocl {
inline void* default_aligned_malloc( size_t size, void* = nullptr )
inline void* malloc64( size_t size, void* = nullptr )
{
return size == 0 ? 0 : _mm_malloc( size, 64 );
}
inline void default_aligned_free( void* ptr, void* = nullptr ) { _mm_free( ptr ); }
inline void free64( void* ptr, void* = nullptr ) { _mm_free( ptr ); }
}
#else
namespace tinyocl {
inline void* default_aligned_malloc( size_t size, void* = nullptr )
inline void* malloc64( size_t size, void* = nullptr )
{
return size == 0 ? 0 : aligned_alloc( 64, make_multiple_64( size ) );
}
inline void default_aligned_free( void* ptr, void* = nullptr ) { free( ptr ); }
inline void free64( void* ptr, void* = nullptr ) { free( ptr ); }
}
#endif
#else // gcc / clang
#define ALIGNED( x ) __attribute__( ( aligned( x ) ) )
#if defined(__x86_64__) || defined(_M_X64)
#include <xmmintrin.h>
namespace tinyocl {
inline void* default_aligned_malloc( size_t size, void* = nullptr )
inline void* malloc64( size_t size, void* = nullptr )
{
return size == 0 ? 0 : _mm_malloc( make_multiple_64( size ), 64 );
}
inline void default_aligned_free( void* ptr, void* = nullptr ) { _mm_free( ptr ); }
inline void free64( void* ptr, void* = nullptr ) { _mm_free( ptr ); }
}
#else
namespace tinyocl {
inline void* default_aligned_malloc( size_t size, void* = nullptr )
inline void* malloc64( size_t size, void* = nullptr )
{
return size == 0 ? 0 : aligned_alloc( 64, make_multiple_64( size ) );
}
inline void default_aligned_free( void* ptr, void* = nullptr ) { free( ptr ); }
inline void free64( void* ptr, void* = nullptr ) { free( ptr ); }
}
#endif
#endif
Expand Down Expand Up @@ -122,8 +122,8 @@ struct oclvec3 { float x, y, z; };
// kernel) will take care of this for you transparently.
struct OpenCLContext
{
void* (*malloc)(size_t size, void* userdata) = default_aligned_malloc;
void (*free)(void* ptr, void* userdata) = default_aligned_free;
void* (*malloc)(size_t size, void* userdata) = malloc64;
void (*free)(void* ptr, void* userdata) = free64;
void* userdata = nullptr;
};
class OpenCL
Expand Down

0 comments on commit a40718f

Please sign in to comment.