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

bernardladenthin / BitcoinAddressFinder / #287

12 Apr 2025 09:07AM UTC coverage: 67.536% (+3.4%) from 64.134%
#287

push

bernardladenthin
Add assumeOpenCLLibraryLoadable.

1165 of 1725 relevant lines covered (67.54%)

0.68 hits per line

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

20.0
/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.charset.Charset;
25
import org.apache.maven.artifact.versioning.ComparableVersion;
26
import org.jocl.CL;
27

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

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

146
        return baos.toString(charset);
×
147
    }
148
    
149
    public static String formatWorkItemSizes(long[] sizes) {
150
        if (sizes == null || sizes.length == 0) return "(none)";
1✔
151
        StringBuilder sb = new StringBuilder();
1✔
152
        for (int i = 0; i < sizes.length; i++) {
1✔
153
            sb.append(sizes[i]);
1✔
154
            if (i < sizes.length - 1) sb.append(" / ");
1✔
155
        }
156
        return sb.toString();
1✔
157
    }
158
    
159
    public ComparableVersion getDeviceVersionAsComparableVersion() {
160
        return getComparableVersionFromDeviceVersion(deviceVersion());
×
161
    }
162
    
163
    public static ComparableVersion getComparableVersionFromDeviceVersion(String deviceVersion) {
164
        String s = deviceVersion;
1✔
165
        s = s.replace("OpenCL ", "");
1✔
166
        s = s.replace("CUDA", "");
1✔
167
        return new ComparableVersion(s.trim());
1✔
168
    }
169
}
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