cmp_pb = CBuffer()
    cmp_particles = st.makeCopy(initial_particles, cbuffer=cmp_pb)
    cmp_pbuffer = st_Buffer_new_mapped_on_cbuffer(cmp_pb)
    assert (cmp_pbuffer != st_NullBuffer)

    ret = st_BeamMonitor_assign_output_cbuffer(eb, cmp_output_buffer,
                                               min_turn_id,
                                               until_turn_elem_by_elem)

    lattice = st_Buffer_new_mapped_on_cbuffer(eb)
    assert (lattice != st_NullBuffer)

    until_turn = 10

    st_Track_all_particles_until_turn(
        st_Particles_buffer_get_particles(cmp_pbuffer, 0), lattice,
        ct.c_int64(until_turn))

    st_Buffer_delete(lattice)
    lattice = st_NullBuffer

    job = st.TrackJob(eb, track_pb, int(0), arch, device)

    num_beam_elements = eb.n_objects
    num_lattice_parts = 10
    num_elem_per_part = num_beam_elements // num_lattice_parts

    for ii in range(until_turn):
        for jj in range(num_lattice_parts):
            is_last_in_turn = bool(jj == (num_lattice_parts - 1))
            begin_idx = jj * num_elem_per_part
    NUM_TURNS = 10
    PSET_INDEX = 0

    # ==========================================================================
    # Perform "regular" tracking over NUM_TURNS

    cmp_track_pb = st.Buffer(cbuffer=cmp_pb)
    assert cmp_track_pb.pointer != st_NullBuffer
    assert cmp_track_pb.num_objects == cmp_pb.n_objects

    cmp_eb = st.Buffer(cbuffer=eb)
    assert cmp_eb.pointer != st_NullBuffer
    assert cmp_eb.num_objects == num_beam_elements

    _pset_index = st_buffer_size_t(PSET_INDEX)
    cmp_particles = st_Particles_buffer_get_particles(
        cmp_track_pb.pointer, _pset_index)
    assert cmp_particles != st_NullParticles

    _num_turns = ct.c_int64(NUM_TURNS)
    track_status = st_Track_all_particles_until_turn(
        cmp_particles, cmp_eb.pointer, _num_turns)

    assert track_status == st_TRACK_SUCCESS.value

    # =========================================================================
    # Setup CudaTrackJob to perform the same tracking on the same data but
    # line by line wise:

    track_job = st.CudaTrackJob(eb, pb, PSET_INDEX)

    assert track_job.arch_str == "cuda"
    # put buffer to a set of different buffers -> so we can keep track of them

    ptr_pb = st_Buffer_new_mapped_on_cbuffer(pb.cbuffer)
    assert ptr_pb != st_NullBuffer

    ptr_line = st_Buffer_new_mapped_on_cbuffer(line.cbuffer)
    assert ptr_line != st_NullBuffer

    ptr_output = st_Buffer_new_mapped_on_cbuffer(job.output.cbuffer)
    assert ptr_output != st_NullBuffer

    init_pb = st_Buffer_new_from_copy(ptr_pb)
    assert init_pb != st_NullBuffer
    assert st_Buffer_get_num_of_objects(init_pb) == pb.cbuffer.n_objects

    ptr_init_particles = st_Particles_buffer_get_particles(
        init_pb, ct.c_uint64(0))
    assert ptr_init_particles != st_NullParticles
    assert 0 == st_Particles_compare_values(ptr_particles, ptr_init_particles)

    init_line = st_Buffer_new_from_copy(ptr_line)
    assert init_line != st_NullBuffer
    assert st_Buffer_get_num_of_objects(init_line) == \
        line.cbuffer.n_objects

    init_output = st_Buffer_new_from_copy(ptr_output)
    assert init_output != st_NullBuffer
    assert st_Buffer_get_num_of_objects(init_output) == \
        job.output.cbuffer.n_objects

    # Locally change the contents of the line, the particle buffer and the
    # output buffer after the job has been created -> we will push these
    st.st_Track_particles_line_cuda_on_grid(
        st.st_CudaArgument_get_arg_buffer(particles_arg),
        st.st_CudaArgument_get_arg_buffer(lattice_arg),
        line_middle, line_end, ct.c_bool(True),
        num_blocks, threads_per_block)

    success = st.st_CudaArgument_receive_buffer(particles_arg, pbuffer)
    assert success == 0

    cmp_pb = CBuffer()
    cmp_particles = pyst.makeCopy(initial_particles, cbuffer=cmp_pb)
    cmp_pbuffer = st.st_Buffer_new_mapped_on_cbuffer(cmp_pb)
    assert cmp_pbuffer != st.st_NullBuffer

    st.st_Track_all_particles_until_turn(
        st.st_Particles_buffer_get_particles(cmp_pbuffer, 0),
        lattice, ct.c_int64(1))

    assert pyst.compareParticlesDifference(
        track_pb.get_object(0, cls=pyst.Particles),
        cmp_pb.get_object(0, cls=pyst.Particles),
        abs_treshold=2e-14) == 0

    st.st_CudaArgument_delete(particles_arg)
    st.st_CudaArgument_delete(lattice_arg)
    st.st_CudaContext_delete(ctx)

    st.st_Buffer_delete(pbuffer)
    st.st_Buffer_delete(lattice)
    st.st_Buffer_delete(cmp_pbuffer)
Esempio n. 5
0
    assert track_job.has_particle_addresses

    pb_buffer = st.Buffer(cbuffer=pb)
    assert pb_buffer.pointer != st_NullBuffer
    assert pb_buffer.num_objects == num_particle_sets

    slot_size = pb_buffer.slot_size
    assert slot_size > 0
    _slot_size = st_buffer_size_t(slot_size)

    prev_particle_addr = st_NullParticlesAddr
    for ii in range(0, num_particle_sets):
        particle_addr = track_job.get_particle_addresses(ii)
        assert particle_addr != st_NullParticlesAddr
        assert particle_addr != prev_particle_addr

        cmp_particles = st_Particles_buffer_get_particles(
            pb_buffer.pointer, st_buffer_size_t(ii))

        assert cmp_particles != st_NullParticles
        assert st_Particles_get_num_of_particles(cmp_particles) == \
            particle_addr.contents.num_particles

        assert st_TestParticlesAddr_are_addresses_consistent_with_particle(
            particle_addr, cmp_particles, _slot_size)

        prev_particle_addr = particle_addr

    sys.exit(0)
Esempio n. 6
0
    assert (path_to_testdir is not None)
    assert (os.path.exists(path_to_testdir))
    assert (os.path.isdir(path_to_testdir))

    path_to_particle_data = os.path.join(path_to_testdir, "beambeam",
                                         "particles_dump.bin")
    assert (os.path.exists(path_to_particle_data))

    path_to_beam_elements_data = os.path.join(path_to_testdir, "beambeam",
                                              "beam_elements.bin")
    assert (os.path.exists(path_to_beam_elements_data))

    pb = st.st_Buffer_new_from_file(path_to_particle_data.encode('utf-8'))
    eb = st.st_Buffer_new_from_file(path_to_beam_elements_data.encode('utf-8'))

    particles = st.st_Particles_buffer_get_particles(pb, 0)
    assert (particles != st.st_NullParticles)
    assert (st.st_Particles_get_num_of_particles(particles) > 0)

    num_objects = ct.c_uint64(0)
    num_slots = ct.c_uint64(0)
    num_dataptrs = ct.c_uint64(0)
    num_garbage = ct.c_uint64(0)

    slot_size = st.st_Buffer_get_slot_size(pb)
    num_elem_by_elem_turns = 10

    ret = st.st_OutputBuffer_calculate_output_buffer_params(
        eb, particles, num_elem_by_elem_turns, ct.byref(num_objects),
        ct.byref(num_slots), ct.byref(num_dataptrs), ct.byref(num_garbage),
        slot_size)