• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / JavaSpiNNaker / 6233274834

19 Sep 2023 08:46AM UTC coverage: 36.409% (-0.6%) from 36.982%
6233274834

Pull #658

github

dkfellows
Merge branch 'master' into java-17
Pull Request #658: Update Java version to 17

1656 of 1656 new or added lines in 260 files covered. (100.0%)

8373 of 22997 relevant lines covered (36.41%)

0.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/FillProcess.java
1
/*
2
 * Copyright (c) 2018 The University of Manchester
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package uk.ac.manchester.spinnaker.transceiver;
17

18
import static java.lang.String.format;
19
import static org.slf4j.LoggerFactory.getLogger;
20
import static uk.ac.manchester.spinnaker.messages.Constants.WORD_SIZE;
21
import static uk.ac.manchester.spinnaker.utils.ByteBufferUtils.alloc;
22

23
import java.io.IOException;
24
import java.nio.ByteBuffer;
25

26
import org.slf4j.Logger;
27

28
import uk.ac.manchester.spinnaker.connections.ConnectionSelector;
29
import uk.ac.manchester.spinnaker.connections.SCPConnection;
30
import uk.ac.manchester.spinnaker.machine.HasChipLocation;
31
import uk.ac.manchester.spinnaker.machine.MemoryLocation;
32
import uk.ac.manchester.spinnaker.messages.scp.FillRequest;
33
import uk.ac.manchester.spinnaker.messages.scp.WriteMemory;
34

35
/** A process for filling memory. */
36
final class FillProcess extends TxrxProcess {
37
        private static final Logger log = getLogger(FillProcess.class);
×
38

39
        private static final int ALIGNMENT = 4;
40

41
        private static final int TWO_WORDS = 2 * WORD_SIZE;
42

43
        /**
44
         * Create.
45
         *
46
         * @param connectionSelector
47
         *            How to choose where to send messages.
48
         * @param retryTracker
49
         *            Object used to track how many retries were used in an
50
         *            operation. May be {@code null} if no suck tracking is
51
         *            required.
52
         */
53
        FillProcess(ConnectionSelector<? extends SCPConnection> connectionSelector,
54
                        RetryTracker retryTracker) {
55
                super(connectionSelector, retryTracker);
×
56
        }
×
57

58
        /**
59
         * Fill memory with a value.
60
         *
61
         * @param chip
62
         *            The chip with the memory.
63
         * @param baseAddress
64
         *            The address in memory to start filling at.
65
         * @param data
66
         *            The data to fill.
67
         * @param size
68
         *            The number of bytes to fill.
69
         * @param dataType
70
         *            The type of data to fill with.
71
         * @throws IOException
72
         *             If anything goes wrong with networking.
73
         * @throws ProcessException
74
         *             If SpiNNaker rejects a message.
75
         * @throws InterruptedException
76
         *             If the communications were interrupted.
77
         * @throws IllegalArgumentException
78
         *             If the size doesn't match the alignment of the data type.
79
         */
80
        void fillMemory(HasChipLocation chip, MemoryLocation baseAddress, int data,
81
                        int size, FillDataType dataType)
82
                        throws ProcessException, IOException, InterruptedException {
83
                // Don't do anything if there is nothing to do!
84
                if (size == 0) {
×
85
                        return;
×
86
                }
87

88
                // Check that the data can fill the requested size
89
                if (size % dataType.size != 0) {
×
90
                        throw new IllegalArgumentException(format(
×
91
                                        "The size of %d bytes to fill is not divisible by the "
92
                                                        + "size of the data of %d bytes",
93
                                        size, dataType.size));
×
94
                }
95
                if (!baseAddress.isAligned()) {
×
96
                        log.warn("Unaligned fill starting at {}; please use aligned fills",
×
97
                                        baseAddress);
98
                }
99

100
                // Get a word of data regardless of the type
101
                var buffer = alloc(TWO_WORDS);
×
102
                while (buffer.hasRemaining()) {
×
103
                        dataType.writeTo(data, buffer);
×
104
                }
105
                buffer.flip();
×
106

107
                generateWriteMessages(chip, baseAddress, size, buffer);
×
108

109
                /*
110
                 * Wait for all the packets to be confirmed and then check there are no
111
                 * errors.
112
                 */
113
                finishBatch();
×
114
        }
×
115

116
        private void generateWriteMessages(HasChipLocation chip,
117
                        MemoryLocation base, int size, ByteBuffer buffer)
118
                        throws IOException, InterruptedException {
119
                int toWrite = size;
×
120
                var address = base;
×
121

122
                // Send the pre-data to make the memory aligned, up to the first word.
123
                int extraBytes = (ALIGNMENT - base.subWordAlignment()) % ALIGNMENT;
×
124
                if (extraBytes != 0) {
×
125
                        var preBytes = buffer.duplicate();
×
126
                        preBytes.limit(extraBytes);
×
127
                        // Send the preBytes to make the memory aligned
128
                        if (preBytes.hasRemaining()) {
×
129
                                sendRequest(new WriteMemory(chip, base, preBytes));
×
130
                        }
131
                        toWrite -= extraBytes;
×
132
                        address = address.add(extraBytes);
×
133
                }
134

135
                // Fill as much as possible using the bulk operation, FillRequest
136
                int bulkBytes = (extraBytes != 0) ? size - ALIGNMENT : size;
×
137
                if (bulkBytes != 0) {
×
138
                        sendRequest(new FillRequest(chip, address,
×
139
                                        buffer.getInt(extraBytes), bulkBytes));
×
140
                        toWrite -= bulkBytes;
×
141
                        address.add(bulkBytes);
×
142
                }
143

144
                /*
145
                 * Post bytes is the last part of the data from the end of the last
146
                 * aligned word; send them if required. This uses a WriteMemory
147
                 */
148
                if (toWrite != 0) {
×
149
                        buffer.position(buffer.limit() - base.subWordAlignment());
×
150
                        buffer.limit(buffer.position() + toWrite);
×
151
                        if (buffer.hasRemaining()) {
×
152
                                sendRequest(new WriteMemory(chip, address, buffer));
×
153
                        }
154
                }
155
        }
×
156
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc