Skip to content

Commit

Permalink
Merge pull request #6 from martinschwinzerl/be_tricub
Browse files Browse the repository at this point in the history
Be tricub
  • Loading branch information
kparasch authored Nov 22, 2019
2 parents 58104b0 + 6dc3e5c commit 230cd1d
Show file tree
Hide file tree
Showing 28 changed files with 6,000 additions and 548 deletions.
1 change: 1 addition & 0 deletions python/sixtracklib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
from .control import NodeId, NodeInfoBase, ControllerBase, NodeControllerBase, \
ArgumentBase
from .cuda import CudaArgument, CudaController, CudaNodeInfo, CudaTrackJob
from .opencl import ClController, ClArgument
from .trackjob import TrackJob
from .config_helper import supports
477 changes: 477 additions & 0 deletions python/sixtracklib/opencl.py

Large diffs are not rendered by default.

998 changes: 952 additions & 46 deletions python/sixtracklib/stcommon.py

Large diffs are not rendered by default.

109 changes: 89 additions & 20 deletions python/sixtracklib/trackjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from .stcommon import st_TrackJobBaseNew_p, st_NullTrackJobBaseNew, \
st_ARCH_STATUS_SUCCESS, st_ARCH_STATUS_GENERAL_FAILURE, \
st_TRACK_SUCCESS, st_TRACK_STATUS_GENERAL_FAILURE, \
st_buffer_flags_t, st_arch_size_t, st_BUFFER_DEFAULT_CAPACITY, \
st_BUFFER_DEFAULT_DATASTORE_FLAGS, \
st_Particles_p, st_NullParticles, st_ParticlesAddr, st_NullParticlesAddr, \
st_track_status_t, st_track_job_collect_flag_t, st_track_job_clear_flag_t,\
st_out_buffer_flags_t, st_track_job_size_t, \
Expand Down Expand Up @@ -91,6 +93,16 @@
st_TrackJobNew_uses_controller, st_TrackJobNew_uses_arguments


def _get_buffer(obj):
if isinstance(obj, CBuffer):
return obj
elif isinstance(obj, CObject):
return obj._buffer
elif hasattr(obj, 'cbuffer'):
return obj.cbuffer
else:
raise ValueError("Object {obj} is not or has not a CBuffer")

class TrackJobBaseNew(object):
def __init__(self, ptr_track_job=None, owns_ptr=True):
self._ptr_track_job = st_NullTrackJobBaseNew
Expand All @@ -109,6 +121,7 @@ def __init__(self, ptr_track_job=None, owns_ptr=True):
self._ptr_c_particles_buffer = st_NullBuffer
self._ptr_c_beam_elements_buffer = st_NullBuffer
self._ptr_c_output_buffer = st_NullBuffer
self._ext_stored_buffers = {}

if ptr_track_job is not None and ptr_track_job != st_NullTrackJobBaseNew:
self._ptr_track_job = ptr_track_job
Expand Down Expand Up @@ -466,6 +479,22 @@ def particles_buffer(self):
def beam_elements_buffer(self):
return self._beam_elements_buffer

@property
def has_ext_stored_buffers(self):
return st.st_TrackJob_has_ext_stored_buffers( self._ptr_track_job )

@property
def num_ext_stored_buffers(self):
return st.st_TrackJob_num_ext_stored_buffers( self._ptr_track_job )

@property
def min_ext_stored_buffer_id(self):
return st.st_TrackJob_min_ext_stored_buffer_id( self._ptr_track_job )

@property
def max_ext_stored_buffer_id(self):
return st.st_TrackJob_max_ext_stored_buffer_id( self._ptr_track_job )

# -------------------------------------------------------------------------

def track_until(self, until_turn):
Expand Down Expand Up @@ -636,7 +665,7 @@ def disable_debug_mode(self):
# -------------------------------------------------------------------------

def fetch_particle_addresses(self):
self._last_status = st_TrackJobNew_fetch_particle_addresses(
self._last_status = st.st_TrackJob_fetch_particle_addresses(
self._ptr_track_job)
raise_error_if_status_not_success(
self._last_status,
Expand All @@ -646,7 +675,7 @@ def fetch_particle_addresses(self):
return self

def clear_particle_addresses(self, particle_set_index=0):
self._last_status = st_TrackJobNew_clear_particle_addresses(
self._last_status = st.st_TrackJob_clear_particle_addresses(
self._ptr_track_job, st_buffer_size_t(particle_set_index))
raise_error_if_status_not_success(
self._last_status,
Expand All @@ -657,7 +686,7 @@ def clear_particle_addresses(self, particle_set_index=0):
return self

def clear_all_particle_addresses(self):
self._last_status = st_TrackJobNew_clear_all_particle_addresses(
self._last_status = st.st_TrackJob_clear_all_particle_addresses(
self._ptr_track_job)
raise_error_if_status_not_success(
self._last_status,
Expand All @@ -667,19 +696,60 @@ def clear_all_particle_addresses(self):
return self

def get_particle_addresses(self, particle_set_index=0):
return st_TrackJobNew_get_particle_addresses(
return st.st_TrackJob_get_particle_addresses(
self._ptr_track_job, st_buffer_size_t(particle_set_index))

# -------------------------------------------------------------------------

def add_ext_stored_buffer(self, buffer=None,
capacity=st_BUFFER_DEFAULT_CAPACITY.value,
flags=st_BUFFER_DEFAULT_DATASTORE_FLAGS.value,
ptr_c_buffer_t=None,
take_ownership=False,
delete_ptr_after_move=False ):
buffer_id = st.st_ARCH_ILLEGAL_BUFFER_ID.value
if buffer is not None:
_cbuffer = _get_buffer(buffer)
_ptr_buffer = st.st_Buffer_new_mapped_on_cbuffer(_cbuffer)
if _ptr_buffer != st_NullBuffer:
buffer_id = st.st_TrackJob_add_ext_stored_buffer(
self._ptr_track_job, _ptr_buffer,
ct.c_bool(False), ct.c_bool(False))
if buffer_id != st.st_ARCH_ILLEGAL_BUFFER_ID.value:
self._ext_stored_buffers[ buffer_id ] = _cbuffer

if buffer_id == st.st_ARCH_ILLEGAL_BUFFER_ID.value:
raise ValueError("Unable to add external buffer to TrackJob")

return buffer_id


def remove_ext_stored_buffer(self, buffer_id):
return st.st_TrackJob_remove_ext_stored_buffer(
self._ptr_track_job, st_arch_size_t(buffer_id))

def owns_ext_stored_buffer(self, buffer_id):
return st.st_TrackJob_owns_ext_stored_buffer(
self._ptr_track_job, st_arch_size_t(buffer_id))

def ext_stored_buffer(self, buffer_id):
return self._ext_stored_buffers.get(buffer_id, None)

def ptr_ext_stored_buffer(self, buffer_id):
_ptr_buffer = st.st_TrackJob_ext_stored_buffer(
self._ptr_buffer, st_arch_size_t(buffer_id))
if _ptr_buffer != st_NullBuffer:
return Buffer(ptr_ext_buffer=_ptr_buffer, owns_ptr=False)

raise RuntimeError("Unable to retrieve ptr to ext stored buffer")
return st_NullBuffer







def _get_buffer(obj):
if isinstance(obj, CBuffer):
return obj
elif isinstance(obj, CObject):
return obj._buffer
elif hasattr(obj, 'cbuffer'):
return obj.cbuffer
else:
raise ValueError("Object {obj} is not or has not a CBuffer")


from .stcommon import \
Expand All @@ -689,8 +759,7 @@ def _get_buffer(obj):
st_ClContextBase_enable_kernel, st_ClContextBase_find_kernel_id_by_name, \
st_ClContext_assign_addresses, st_ClContextBase_assign_kernel_argument, \
st_ClContextBase_assign_kernel_argument_value, \
st_TrackJobCl_p, st_NullTrackJob, st_TrackJobCl_get_context, \
st_AssignAddressItem_assign_all
st_TrackJobCl_p, st_NullTrackJob, st_TrackJobCl_get_context

class TrackJob(object):
@staticmethod
Expand Down Expand Up @@ -933,12 +1002,11 @@ def _push_output(self):

@property
def can_fetch_particle_addresses(self):
return st.st_TrackJob_can_fetch_particle_addresses(
self.ptr_st_track_job)
return st.st_TrackJob_can_fetch_particles_addr( self.ptr_st_track_job)

@property
def has_particle_addresses(self):
return st.st_TrackJob_has_particle_addresses(self.ptr_st_track_job)
return st.st_TrackJob_has_particles_addr(self.ptr_st_track_job)

def type(self):
return st.st_TrackJob_get_type_id(self.ptr_st_track_job)
Expand Down Expand Up @@ -1056,8 +1124,9 @@ def assign_addresses(self, assignment_buffer, dest_buffer, source_buffer):
st_ClArgument_delete( _src_arg )

elif self.arch_str == 'cpu':
success = st_AssignAddressItem_assign_all(
_assign_buffer, _dest_buffer, _src_buffer )
pass
#success = st_AssignAddressItem_assign_all(
#_assign_buffer, _dest_buffer, _src_buffer )

if _assign_buffer != st_NullBuffer:
st.st_Buffer_delete( _assign_buffer )
Expand Down
43 changes: 43 additions & 0 deletions sixtracklib/common/be_tricub/coefficients.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef SIXTRACKLIB_COMMON_BE_TRICUB_COEFFICIENTS_C99_H__
#define SIXTRACKLIB_COMMON_BE_TRICUB_COEFFICIENTS_C99_H__

/*
#if !defined(SIXTRL_NO_SYSTEM_INCLUDES)
#include <stddef.h>
#include <math.h>
#endif */
/* !defined(SIXTRL_NO_SYSTEM_INCLUDES) */

#if !defined(SIXTRL_NO_INCLUDES)
#include "sixtracklib/common/definitions.h"
#include "sixtracklib/common/be_tricub/be_tricub.h"
#endif /* !defined(SIXTRL_NO_INCLUDES) */

#if !defined( _GPUCODE ) && defined( __cplusplus )
extern "C" {
#endif /* !defined( _GPUCODE ) && defined( __cplusplus ) */

/* SUGGESTION: Up here only the signatures / declarations */

#if !defined( _GPUCODE ) && defined( __cplusplus )
}
#endif /* !defined( _GPUCODE ) && defined( __cplusplus ) */

/* ************************************************************************* */
/* ************************************************************************* */

#if !defined( _GPUCODE ) && defined( __cplusplus )
extern "C" {
#endif /* !defined( _GPUCODE ) && defined( __cplusplus ) */

/* SUGGESTION: Up here the inline declrations
INLINE: SIXTRL_INLINE and SIXTRL_STATIC SIXTRL_FN above
*/

#if !defined( _GPUCODE ) && defined( __cplusplus )
}
#endif /* !defined( _GPUCODE ) && defined( __cplusplus ) */

#endif /* SIXTRACKLIB_COMMON_BE_TRICUB_COEFFICIENTS_C99_H__ */


74 changes: 63 additions & 11 deletions sixtracklib/common/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <stdexcept>
#include <limits>
#include <utility>
#include <memory>
#include <stdexcept>
#include <string>
#include <utility>
#endif /* defined( __cplusplus ) */
#endif /* !defined( SIXTRL_NO_SYSTEM_INCLUDES ) */

Expand Down Expand Up @@ -45,6 +46,15 @@ namespace SIXTRL_CXX_NAMESPACE
SIXTRL_STATIC_VAR SIXTRL_CONSTEXPR_OR_CONST flags_t
DEFAULT_DATASTORE_FLAGS = ::NS(BUFFER_DATASTORE_MEMPOOL);

#if !defined( _GPUCODE )

SIXTRL_STATIC std::unique_ptr< Buffer >
MAKE_FROM_CBUFFER_AND_TAKE_OWNERSHIP(
::NS(Buffer)* SIXTRL_RESTRICT ptr_to_take_ownership,
bool const delete_ptr_after_move = true );

#endif /* !defined( _GPUCODE ) */

SIXTRL_FN SIXTRL_STATIC size_type CalculateBufferSize(
size_type max_num_objects, size_type max_num_slots,
size_type max_num_dataptrs, size_type max_num_garbage_ranges,
Expand Down Expand Up @@ -240,13 +250,13 @@ namespace SIXTRL_CXX_NAMESPACE
get( size_type const object_index ) SIXTRL_NOEXCEPT;

/* ----------------------------------------------------------------- */

SIXTRL_FN bool reset(
size_type const max_num_objects = size_type{ 0 },
size_type const max_num_slots = size_type{ 0 },
size_type const max_num_dataptrs = size_type{ 0 },
size_type const max_num_garbage_ranges = size_type{ 0 } );

/* ----------------------------------------------------------------- */

SIXTRL_FN bool needsRemapping() const SIXTRL_NOEXCEPT;
Expand Down Expand Up @@ -288,7 +298,7 @@ namespace SIXTRL_CXX_NAMESPACE
return T::AddToBuffer(
*this->getCApiPtr(), std::forward< Args >( args )... );
}

template< class T >
SIXTRL_FN T* addCopy( T const& SIXTRL_RESTRICT_REF other )
{
Expand Down Expand Up @@ -341,6 +351,42 @@ namespace SIXTRL_CXX_NAMESPACE

namespace SIXTRL_CXX_NAMESPACE
{
#if !defined( _GPUCODE )

SIXTRL_INLINE std::unique_ptr< Buffer >
Buffer::MAKE_FROM_CBUFFER_AND_TAKE_OWNERSHIP(
::NS(Buffer)* SIXTRL_RESTRICT ptr_to_take_ownership,
bool const delete_ptr_after_move )
{
namespace st = SIXTRL_CXX_NAMESPACE;
std::unique_ptr< st::Buffer > ptr_cxx_buffer( nullptr );

if( ptr_to_take_ownership != nullptr )
{
using size_t = st::Buffer::size_type;
using ptr_to_raw_t = SIXTRL_ARGPTR_DEC unsigned char*;

ptr_cxx_buffer.reset( new st::Buffer(
ptr_to_raw_t{ nullptr }, size_t{ 0u } ) );
SIXTRL_ASSERT( ptr_cxx_buffer.get() != nullptr );

::NS(Buffer)* ptr_c_buffer = ptr_cxx_buffer->getCApiPtr();
SIXTRL_ASSERT( ptr_c_buffer != nullptr );

*ptr_c_buffer = *ptr_to_take_ownership;
::NS(Buffer_preset)( ptr_to_take_ownership );

if( delete_ptr_after_move )
{
::NS(Buffer_delete)( ptr_to_take_ownership );
}
}

return ptr_cxx_buffer;
}

#endif /* !defined( _GPUCODE ) */

SIXTRL_INLINE Buffer::size_type Buffer::CalculateBufferSize(
Buffer::size_type const max_num_objects,
Buffer::size_type const max_num_slots,
Expand Down Expand Up @@ -413,14 +459,20 @@ namespace SIXTRL_CXX_NAMESPACE
::NS(Buffer)()
{
using c_api_t = Buffer::c_api_t;
using size_t = Buffer::size_type;
using ptr_to_raw_t = SIXTRL_ARGPTR_DEC unsigned char*;

c_api_t* _buffer = ::NS(Buffer_preset)( this->getCApiPtr() );
ptr_to_raw_t _data_begin = reinterpret_cast< ptr_to_raw_t >(
data_buffer_begin );

if( 0 != ::NS(Buffer_init)( _buffer, reinterpret_cast< ptr_to_raw_t >(
data_buffer_begin ), max_buffer_size ) )
if( ( _data_begin != nullptr ) || ( max_buffer_size > size_t{ 0 } ) )
{
::NS(Buffer_free)( _buffer );
if( 0 != ::NS(Buffer_init)(
_buffer, _data_begin, max_buffer_size ) )
{
::NS(Buffer_free)( _buffer );
}
}
}

Expand Down Expand Up @@ -1096,18 +1148,18 @@ namespace SIXTRL_CXX_NAMESPACE
}

/* ----------------------------------------------------------------- */

SIXTRL_INLINE bool Buffer::reset(
Buffer::size_type const max_num_objects,
Buffer::size_type const max_num_slots,
Buffer::size_type const max_num_dataptrs,
Buffer::size_type const max_num_garbage_ranges )
{
return ( ::NS(Buffer_reset_detailed)( this->getCApiPtr(),
max_num_objects, max_num_slots, max_num_dataptrs,
max_num_objects, max_num_slots, max_num_dataptrs,
max_num_garbage_ranges ) == 0 );
}

/* ----------------------------------------------------------------- */

SIXTRL_INLINE bool Buffer::needsRemapping() const SIXTRL_NOEXCEPT
Expand Down
Loading

0 comments on commit 230cd1d

Please sign in to comment.