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

bernardladenthin / BitcoinAddressFinder / #308

28 Apr 2025 10:01PM UTC coverage: 68.174% (-0.7%) from 68.832%
#308

push

bernardladenthin
Refactor OpenCL handling for device endianness and dynamic platform selection

22 of 76 new or added lines in 10 files covered. (28.95%)

1 existing line in 1 file now uncovered.

1221 of 1791 relevant lines covered (68.17%)

0.68 hits per line

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

18.18
/src/main/java/net/ladenthin/bitcoinaddressfinder/opencl/OpenCLDevice.java
1
// @formatter:off
2
/**
3
 * Copyright 2022 Bernard Ladenthin bernard.ladenthin@gmail.com
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *    http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 */
18
// @formatter:on
19
package net.ladenthin.bitcoinaddressfinder.opencl;
20

21
import java.io.ByteArrayOutputStream;
22
import java.io.PrintStream;
23
import java.io.Serializable;
24
import java.nio.ByteOrder;
25
import java.nio.charset.Charset;
26
import org.apache.maven.artifact.versioning.ComparableVersion;
27
import org.jocl.CL;
28
import org.jocl.cl_device_id;
29

30
/**
31
 * Represents an OpenCL device and its properties.
32
 *
33
 * @param device                     See {@link org.jocl.cl_device_id}
34
 * @param deviceName                 See {@link org.jocl.CL#CL_DEVICE_NAME}
35
 * @param deviceVendor               See {@link org.jocl.CL#CL_DEVICE_VENDOR}
36
 * @param driverVersion              See {@link org.jocl.CL#CL_DRIVER_VERSION}
37
 * @param deviceProfile              See {@link org.jocl.CL#CL_DEVICE_PROFILE}
38
 * @param deviceVersion              See {@link org.jocl.CL#CL_DEVICE_VERSION}
39
 * @param deviceExtensions           See {@link org.jocl.CL#CL_DEVICE_EXTENSIONS}
40
 * @param deviceType                 See {@link org.jocl.CL#CL_DEVICE_TYPE}
41
 * @param endianLittle               See {@link org.jocl.CL#CL_DEVICE_ENDIAN_LITTLE}
42
 * @param maxComputeUnits            See {@link org.jocl.CL#CL_DEVICE_MAX_COMPUTE_UNITS}
43
 * @param maxWorkItemDimensions      See {@link org.jocl.CL#CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS}
44
 * @param maxWorkItemSizes           See {@link org.jocl.CL#CL_DEVICE_MAX_WORK_ITEM_SIZES}
45
 * @param maxWorkGroupSize           See {@link org.jocl.CL#CL_DEVICE_MAX_WORK_GROUP_SIZE}
46
 * @param maxClockFrequency          See {@link org.jocl.CL#CL_DEVICE_MAX_CLOCK_FREQUENCY}
47
 * @param addressBits                See {@link org.jocl.CL#CL_DEVICE_ADDRESS_BITS}
48
 * @param maxMemAllocSize            See {@link org.jocl.CL#CL_DEVICE_MAX_MEM_ALLOC_SIZE}
49
 * @param globalMemSize              See {@link org.jocl.CL#CL_DEVICE_GLOBAL_MEM_SIZE}
50
 * @param errorCorrectionSupport     See {@link org.jocl.CL#CL_DEVICE_ERROR_CORRECTION_SUPPORT}
51
 * @param localMemType               See {@link org.jocl.CL#CL_DEVICE_LOCAL_MEM_TYPE}
52
 * @param localMemSize               See {@link org.jocl.CL#CL_DEVICE_LOCAL_MEM_SIZE}
53
 * @param maxConstantBufferSize      See {@link org.jocl.CL#CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE}
54
 * @param queueProperties            See {@link org.jocl.CL#CL_DEVICE_QUEUE_PROPERTIES}
55
 * @param imageSupport               See {@link org.jocl.CL#CL_DEVICE_IMAGE_SUPPORT}
56
 * @param maxReadImageArgs           See {@link org.jocl.CL#CL_DEVICE_MAX_READ_IMAGE_ARGS}
57
 * @param maxWriteImageArgs          See {@link org.jocl.CL#CL_DEVICE_MAX_WRITE_IMAGE_ARGS}
58
 * @param singleFpConfig             See {@link org.jocl.CL#CL_DEVICE_SINGLE_FP_CONFIG}
59
 * @param image2dMaxWidth            See {@link org.jocl.CL#CL_DEVICE_IMAGE2D_MAX_WIDTH}
60
 * @param image2dMaxHeight           See {@link org.jocl.CL#CL_DEVICE_IMAGE2D_MAX_HEIGHT}
61
 * @param image3dMaxWidth            See {@link org.jocl.CL#CL_DEVICE_IMAGE3D_MAX_WIDTH}
62
 * @param image3dMaxHeight           See {@link org.jocl.CL#CL_DEVICE_IMAGE3D_MAX_HEIGHT}
63
 * @param image3dMaxDepth            See {@link org.jocl.CL#CL_DEVICE_IMAGE3D_MAX_DEPTH}
64
 * @param preferredVectorWidthChar   See {@link org.jocl.CL#CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR}
65
 * @param preferredVectorWidthShort  See {@link org.jocl.CL#CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT}
66
 * @param preferredVectorWidthInt    See {@link org.jocl.CL#CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT}
67
 * @param preferredVectorWidthLong   See {@link org.jocl.CL#CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG}
68
 * @param preferredVectorWidthFloat  See {@link org.jocl.CL#CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT}
69
 * @param preferredVectorWidthDouble See {@link org.jocl.CL#CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE}
70
 */
71
public record OpenCLDevice(
×
72
    cl_device_id device,
73
    String deviceName,
74
    String deviceVendor,
75
    String driverVersion,
76
    String deviceProfile,
77
    String deviceVersion,
78
    String deviceExtensions,
79
    long deviceType,
80
    boolean endianLittle,
81
    int maxComputeUnits,
82
    long maxWorkItemDimensions,
83
    long[] maxWorkItemSizes,
84
    long maxWorkGroupSize,
85
    long maxClockFrequency,
86
    int addressBits,
87
    long maxMemAllocSize,
88
    long globalMemSize,
89
    long errorCorrectionSupport,
90
    int localMemType,
91
    long localMemSize,
92
    long maxConstantBufferSize,
93
    long queueProperties,
94
    int imageSupport,
95
    int maxReadImageArgs,
96
    int maxWriteImageArgs,
97
    long singleFpConfig,
98
    long image2dMaxWidth,
99
    long image2dMaxHeight,
100
    long image3dMaxWidth,
101
    long image3dMaxHeight,
102
    long image3dMaxDepth,
103
    int preferredVectorWidthChar,
104
    int preferredVectorWidthShort,
105
    int preferredVectorWidthInt,
106
    int preferredVectorWidthLong,
107
    int preferredVectorWidthFloat,
108
    int preferredVectorWidthDouble
109
) implements Serializable {
110
    
111
    public ByteOrder getByteOrder() {
NEW
112
        if(endianLittle) {
×
NEW
113
            return ByteOrder.LITTLE_ENDIAN;
×
114
        }
NEW
115
        return ByteOrder.BIG_ENDIAN;
×
116
    }
117
    
118
    public String toStringPretty() {
119
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
×
120
        final Charset charset = java.nio.charset.StandardCharsets.UTF_8;
×
121

122
        try (PrintStream ps = new PrintStream(baos, true, charset)) {
×
123
            ps.println("--- Info for OpenCL device: " + deviceName + " ---");
×
NEW
124
            ps.printf("cl_device_id:                          %s%n", device);
×
125
            ps.printf("CL_DEVICE_NAME:                        %s%n", deviceName);
×
126
            ps.printf("CL_DEVICE_VENDOR:                      %s%n", deviceVendor);
×
127
            ps.printf("CL_DRIVER_VERSION:                     %s%n", driverVersion);
×
128
            ps.printf("CL_DEVICE_PROFILE:                     %s%n", deviceProfile);
×
129
            ps.printf("CL_DEVICE_VERSION:                     %s%n", deviceVersion);
×
130
            ps.printf("CL_DEVICE_EXTENSIONS:                  %s%n", deviceExtensions);
×
131
            ps.printf("CL_DEVICE_TYPE:                        %s%n", CL.stringFor_cl_device_type(deviceType));
×
NEW
132
            ps.printf("CL_DEVICE_ENDIAN_LITTLE:               %b%n", endianLittle);
×
133
            ps.printf("CL_DEVICE_MAX_COMPUTE_UNITS:           %d%n", maxComputeUnits);
×
134
            ps.printf("CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS:    %d%n", maxWorkItemDimensions);
×
135
            ps.printf("CL_DEVICE_MAX_WORK_ITEM_SIZES:         %s%n", formatWorkItemSizes(maxWorkItemSizes));
×
136
            ps.printf("CL_DEVICE_MAX_WORK_GROUP_SIZE:         %d%n", maxWorkGroupSize);
×
137
            ps.printf("CL_DEVICE_MAX_CLOCK_FREQUENCY:         %d MHz%n", maxClockFrequency);
×
138
            ps.printf("CL_DEVICE_ADDRESS_BITS:                %d%n", addressBits);
×
139
            ps.printf("CL_DEVICE_MAX_MEM_ALLOC_SIZE:          %d MByte%n", maxMemAllocSize / (1024 * 1024));
×
140
            ps.printf("CL_DEVICE_GLOBAL_MEM_SIZE:             %d MByte%n", globalMemSize / (1024 * 1024));
×
141
            ps.printf("CL_DEVICE_ERROR_CORRECTION_SUPPORT:    %s%n", errorCorrectionSupport != 0 ? "yes" : "no");
×
142
            ps.printf("CL_DEVICE_LOCAL_MEM_TYPE:              %s%n", CL.stringFor_cl_device_local_mem_type(localMemType));
×
143
            ps.printf("CL_DEVICE_LOCAL_MEM_SIZE:              %d KByte%n", localMemSize / 1024);
×
144
            ps.printf("CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE:    %d KByte%n", maxConstantBufferSize / 1024);
×
145
            ps.printf("CL_DEVICE_QUEUE_PROPERTIES:            %s%n", CL.stringFor_cl_command_queue_properties(queueProperties));
×
146
            ps.printf("CL_DEVICE_IMAGE_SUPPORT:               %d%n", imageSupport);
×
147
            ps.printf("CL_DEVICE_MAX_READ_IMAGE_ARGS:         %d%n", maxReadImageArgs);
×
148
            ps.printf("CL_DEVICE_MAX_WRITE_IMAGE_ARGS:        %d%n", maxWriteImageArgs);
×
149
            ps.printf("CL_DEVICE_SINGLE_FP_CONFIG:            %s%n", CL.stringFor_cl_device_fp_config(singleFpConfig));
×
150
            ps.printf("CL_DEVICE_IMAGE2D_MAX_WIDTH:           %d%n", image2dMaxWidth);
×
151
            ps.printf("CL_DEVICE_IMAGE2D_MAX_HEIGHT:          %d%n", image2dMaxHeight);
×
152
            ps.printf("CL_DEVICE_IMAGE3D_MAX_WIDTH:           %d%n", image3dMaxWidth);
×
153
            ps.printf("CL_DEVICE_IMAGE3D_MAX_HEIGHT:          %d%n", image3dMaxHeight);
×
154
            ps.printf("CL_DEVICE_IMAGE3D_MAX_DEPTH:           %d%n", image3dMaxDepth);
×
155
            ps.printf("CL_DEVICE_PREFERRED_VECTOR_WIDTHS:     CHAR %d, SHORT %d, INT %d, LONG %d, FLOAT %d, DOUBLE %d%n",
×
156
                preferredVectorWidthChar, preferredVectorWidthShort,
×
157
                preferredVectorWidthInt, preferredVectorWidthLong,
×
158
                preferredVectorWidthFloat, preferredVectorWidthDouble);
×
159
        }
160

161
        return baos.toString(charset);
×
162
    }
163
    
164
    public static String formatWorkItemSizes(long[] sizes) {
165
        if (sizes == null || sizes.length == 0) return "(none)";
1✔
166
        StringBuilder sb = new StringBuilder();
1✔
167
        for (int i = 0; i < sizes.length; i++) {
1✔
168
            sb.append(sizes[i]);
1✔
169
            if (i < sizes.length - 1) sb.append(" / ");
1✔
170
        }
171
        return sb.toString();
1✔
172
    }
173
    
174
    public ComparableVersion getDeviceVersionAsComparableVersion() {
175
        return getComparableVersionFromDeviceVersion(deviceVersion());
×
176
    }
177
    
178
    public static ComparableVersion getComparableVersionFromDeviceVersion(String deviceVersion) {
179
        String s = deviceVersion;
1✔
180
        s = s.replace("OpenCL ", "");
1✔
181
        s = s.replace("CUDA", "");
1✔
182
        return new ComparableVersion(s.trim());
1✔
183
    }
184
}
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