Cipher-text execution method and device for three-dimensional stride convolution and storage medium

By performing phase partitioning and index optimization on the ciphertext execution method in 3D convolution operations, the problem of slot waste is solved and the efficiency of ciphertext convolution operations is improved.

CN122863622BActive Publication Date: 2026-11-24OPEN SECURITY RES INC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202611370571.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-09-04
Publication Date
2026-11-24
Estimated Expiration
2046-09-04

Smart Images

  • Figure CN122863622B_ABST
    Figure CN122863622B_ABST
Patent Text Reader

Abstract

This application provides a method, apparatus, and storage medium for encrypted execution of 3D stride convolution. The method includes: performing phase partitioning on the output encrypted coordinates of the previous convolution round based on the phase stride of the current convolution round to obtain the phase block shape and compact spatial block shape of the current convolution round; determining the input phase coordinates and input compact coordinates of the current convolution round based on the output spatial coordinates, phase stride, and convolution parameters of the current convolution round; determining the input encrypted index, source slot index, and target slot index of the current convolution round based on the input phase coordinates, phase block shape, input compact coordinates, and compact spatial block shape; performing convolution operation on the encrypted text corresponding to the input encrypted index of the current convolution round based on the source slot index and target slot index to obtain the output encrypted text of the current convolution round, and storing the output encrypted text of the current convolution round in the slot corresponding to the target slot index.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to fully homomorphic encrypted inference technology for three-dimensional convolutional neural networks, and more particularly to a ciphertext execution method, apparatus and storage medium for three-dimensional stride convolution. Background Technology

[0002] With the increasing demand for privacy protection, fully homomorphic encryption (FHE) is widely used in deep learning inference tasks to perform convolution operations in encrypted form, ensuring that user data is not leaked. In practical deployments, 3D convolutional neural networks (3D-CNNs) are the core convolution operators, which can be used for encrypted convolution operations in scenarios such as medical image analysis, video understanding, and 3D industrial inspection.

[0003] When performing convolution operations under homomorphic encryption based on ciphertext, relevant schemes directly flatten a single three-dimensional channel into a one-dimensional slot: slot=d H W+h W+w, where slot is the slot index, d is the depth coordinate, H is the height, W is the width, h is the height coordinate, W is the width coordinate, and w is the width coordinate. The kernel offset (KD, KH, KW) corresponds to a fixed rotation: delta = KD H W+KH W+KW, where delta is the slot offset, KD is the kernel depth offset, KH is the kernel height offset, and KW is the kernel width offset. Then, through ciphertext rotation, multiplication with plaintext weights and mask, and accumulation, the ciphertext convolution output is obtained. This results in a low effective slot ratio and significant slot waste. Summary of the Invention

[0004] This application provides a method, apparatus, and storage medium for encrypted execution of three-dimensional stride convolution, which can avoid the generation of invalid output slots and increase the effective proportion of slots.

[0005] The technical solution of this application embodiment is implemented as follows: This application provides a method for encrypted execution of three-dimensional stride convolution, the method comprising: Based on the phase stride of the current convolutional epoch, the output ciphertext coordinates of the previous convolutional epoch are phase-divided to obtain the phase block shape and compact spatial block shape of the current convolutional epoch; the phase stride includes the input phase stride and the output phase stride; the output phase stride is obtained based on the input phase stride; Obtain the output space coordinates of the current convolutional epoch, and determine the input phase coordinates and input compact coordinates of the current convolutional epoch based on the output space coordinates of the current convolutional epoch, the phase stride of the current convolutional epoch, and the convolution parameters of the current convolutional epoch. Based on the input phase coordinates, phase block shape, input compact coordinates, and compact spatial block shape of the current convolutional epoch, determine the input ciphertext index, source slot index, and target slot index of the current convolutional epoch. Based on the source slot index and target slot index of the current convolutional epoch, a convolution operation is performed on the ciphertext corresponding to the input ciphertext index of the current convolutional epoch to obtain the output ciphertext of the current convolutional epoch, and the output ciphertext of the current convolutional epoch is stored in the slot corresponding to the target slot index.

[0006] This application provides a encrypted execution device for three-dimensional stride convolution, the device comprising: The first determining unit is used to perform phase partitioning on the output ciphertext coordinates of the previous convolutional iteration based on the phase stride of the current convolutional iteration, to obtain the phase block shape and compact spatial block shape of the current convolutional iteration; the phase stride includes the input phase stride and the output phase stride; the output phase stride is obtained based on the input phase stride; The second determining unit is used to obtain the output space coordinates of the current convolutional epoch, and determine the input phase coordinates and input compact coordinates of the current convolutional epoch based on the output space coordinates of the current convolutional epoch, the phase stride of the current convolutional epoch, and the convolution parameters of the current convolutional epoch. The third determining unit is used to determine the input ciphertext index, source slot index, and target slot index of the current convolutional epoch based on the input phase coordinates, phase block shape, input compact coordinates, and compact spatial block shape of the current convolutional epoch. The convolution operation unit is used to perform convolution operation on the ciphertext corresponding to the input ciphertext index of the current convolution epoch based on the source slot index and the target slot index of the current convolution epoch, to obtain the output ciphertext of the current convolution epoch, and to store the output ciphertext of the current convolution epoch in the slot corresponding to the target slot index.

[0007] This application provides a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a processor, it implements some or all of the steps in the above method.

[0008] The embodiments of this application have the following beneficial effects: When performing encrypted convolution operations based on 3D-CNN convolution operators in scenarios such as medical image analysis, video understanding, and 3D industrial inspection, the input phase coordinates and input compact coordinates are determined according to the output spatial coordinates, phase stride, and convolution parameters of the current convolution round; the input encrypted index, source slot index, and target slot index are determined according to the input phase coordinates, phase block shape, input compact coordinates, and compact spatial block shape; thus, the encrypted text corresponding to the input encrypted index is convolved based on the source slot index and the target slot index, and the output encrypted text after convolution is stored in the slot corresponding to the target slot index, so that the output encrypted text directly falls in the slot corresponding to the target slot index, thereby avoiding the generation of invalid output slots and improving the effective proportion of slots. Attached Figure Description

[0009] Figure 1 This is a flowchart illustrating the steps of a ciphertext execution method for three-dimensional stride convolution provided in an embodiment of this application. Figure 2 This is a schematic diagram of the deployment method of a three-dimensional convolutional model based on fully homomorphic encryption and a flowchart of the ciphertext inference steps provided in this application embodiment; Figure 3 This is a schematic diagram of a three-dimensional phase state and phase priority ciphertext sorting provided in an embodiment of this application; Figure 4 This is a schematic diagram of a strided three-dimensional convolution phase change provided in an embodiment of this application; Figure 5 This is a schematic diagram of the structure of a ciphertext execution device for three-dimensional stride convolution provided in an embodiment of this application; Figure 6 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0010] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the specific technical solutions of the application will be further described in detail below with reference to the accompanying drawings of the embodiments of this application. The following embodiments are used to illustrate this application, but are not intended to limit the scope of this application.

[0011] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0012] In the following description, the terms "first," "second," and "third" are used only to distinguish different objects and do not represent a specific order of objects or have any chronological limitation. It is understood that "first," "second," and "third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.

[0013] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0014] The following is a description of the abbreviations and key terms used in this application.

[0015] FHE: Fully Homomorphic Encryption, which allows computations to be performed directly on ciphertext without decryption.

[0016] CKKS: A fully homomorphic encryption scheme that supports approximate arithmetic operations and is suitable for approximate calculations of real or complex numbers.

[0017] N: The core parameter of homomorphic encryption, representing the dimension of the polynomial ring. CKKS ciphertext typically contains N / 2 available slots.

[0018] Slot: The smallest unit in CKKS ciphertext that can independently carry data. When performing homomorphic addition, multiplication, or rotation on a ciphertext, all slots participate in the calculation synchronously in a SIMD manner.

[0019] Ciphertext (CT): Data carriers that have been encoded and encrypted.

[0020] Plaintext (PT): Data carrier that is encoded but not encrypted. In ciphertext inference, convolution weights, boundary masks, biases, etc., are usually used in ciphertext-plaintext multiplication or addition in plaintext form.

[0021] Rotation: A cyclic shift operation on the CKKS ciphertext slots. In 3D convolution, different spatial offsets of the convolution kernel typically correspond to different ciphertext rotation offsets.

[0022] Ciphertext bootstrapping: A noise refresh operation in fully homomorphic encryption used to restore the available multiplication depth of the ciphertext. It is a costly operation in FHE inference.

[0023] 3D feature map: The shape can be represented as C D H The feature tensor W, where C is the number of channels, D is the depth, H is the height, and W is the width. Commonly used in medical imaging, video models, or other 3D convolutional neural networks.

[0024] Conv3D: A three-dimensional convolution operator. Its convolution kernel has three spatial dimensions: depth, height, and width, denoted as KD. KH KW.

[0025] Phase stride: The stride used when splitting 3D spatial coordinates according to the remainders of the depth, height, and width axes, denoted as P=(PD,PH,PW), where PD is the stride in the depth direction, PH is the stride in the height direction, and PW is the stride in the width direction. For a given model, the phase stride is derived based on the model topology and the stride chain of each layer's 3D convolution; the input phase stride and output phase stride are denoted as Pin and Pout, respectively. Slot capacity does not directly determine Pin / Pout, but is used to further determine phase partitioning, compact spatial partitioning, and the number of channels carried by each ciphertext.

[0026] Phase layout state: The complete 3D layout state of the feature map within the ciphertext slots. The input phase layout state is denoted as Sin and includes at least the input phase step size Pin, the input phase block shape and grid, the input compact spatial block shape and grid, and the number of channels carried by each input ciphertext. The output phase layout state is denoted as Sout and includes the corresponding output-side fields. Pin / Pout only represents the phase step size field in the complete layout state and does not include phase block, compact spatial block, or channel organization information.

[0027] Phase: The combination of remainders obtained by taking the modulo of the three-dimensional coordinates (d, h, w), denoted as (d mod PD, h mod PH, w mod PW). Points within the same phase are arranged continuously in compact coordinates, where d is the depth coordinate, h is the height coordinate, and w is the width coordinate.

[0028] Compact coordinates: quotient coordinates obtained by removing the phase from three-dimensional coordinates. For example, d = d_compact. PD+phase_d, where d_compact is the compact coordinate and phase_d is the phase coordinate.

[0029] Phase-first interleaved packing is a method that prioritizes splitting feature maps according to three-dimensional phases, and then packs them into CKKS ciphertext slots within each phase as compact spatial blocks and channel blocks.

[0030] Dynamic phase stride transformation: When a 3D convolution has a convolution stride, the phase stride of the output feature map changes with the convolution stride. For example, if the input phase stride is (4,4,4) and the convolution stride is (2,2,2), the output phase stride can naturally become (2,2,2).

[0031] Phase lane: A sub-grid formed by all spatial points with the same phase in a 3D feature map. For example, the phase lane with phase=(0,0,0) contains all points that satisfy d mod PD=0, h mod PH=0, and w mod PW=0.

[0032] Rotation key: The execution plan key value used to reuse the ciphertext rotation result, which can be represented as (input_ct_idx, delta), where input_ct_idx represents the input ciphertext index and delta represents the slot rotation offset, i.e., the slot offset.

[0033] Figure 1 This is a flowchart illustrating the steps of a ciphertext execution method for three-dimensional stride convolution provided in an embodiment of this application, as follows: Figure 1 As shown, the encrypted execution method for three-dimensional stride convolution provided in this application embodiment may include: S101, based on the phase stride of the current convolutional round, perform phase partitioning on the output ciphertext coordinates of the previous convolutional round to obtain the phase block shape and compact spatial block shape of the current convolutional round.

[0034] Among them, the phase block shape represents the shape of the phase block carried by a single ciphertext, and the compact space block shape represents the shape of the compact space block inside each phase.

[0035] The phase stride includes the input phase stride and the output phase stride. In some embodiments, the input phase stride can be preset, i.e., Pin=(PD,PH,PW); the output phase stride is obtained based on the input phase stride. For example, the input phase stride Pin and the 3D convolution stride conv_stride are divided downwards to obtain the output phase stride Pout, i.e., Pout=Pin / conv_stride.

[0036] In some embodiments, the phase block shape of the current convolutional epoch can be determined based on the input phase stride of the current convolutional epoch; and the compact spatial shape can be determined based on the input phase stride of the current convolutional epoch and the output ciphertext coordinates of the previous convolutional epoch.

[0037] S102, obtain the output space coordinates of the current convolutional epoch, and determine the input phase coordinates and input compact coordinates of the current convolutional epoch based on the output space coordinates of the current convolutional epoch, the phase stride of the current convolutional epoch, and the convolution parameters of the current convolutional epoch.

[0038] The output space coordinates, output_coord, represent the three-dimensional space coordinates; the convolution parameters may include: the three-dimensional convolution stride, kernel offset, and padding.

[0039] In some embodiments, the output phase coordinates and output compact coordinates can be determined first based on the output spatial coordinates and phase stride of the current convolution epoch, and then the input phase coordinates can be determined based on the output phase coordinates, phase stride, and convolution parameters, and the input compact coordinates can be determined based on the output compact coordinates, phase stride, and convolution parameters.

[0040] S103. Based on the input phase coordinates, phase block shape, input compact coordinates, and compact spatial block shape of the current convolutional epoch, determine the input ciphertext index, source slot index, and target slot index of the current convolutional epoch.

[0041] The input ciphertext index represents the ciphertext index used for convolution operations; the source slot index represents the index corresponding to the slot where the ciphertext used for convolution operations is stored before the convolution operations; and the target slot index represents the index corresponding to the slot where the convolution results are stored after the convolution operations.

[0042] In some embodiments, the first phase block coordinates are determined based on the input phase coordinates and the phase block shape, the first compact space block coordinates are determined based on the input compact coordinates and the compact space block shape, and the input ciphertext index is determined based on the first phase block coordinates and the first compact space block coordinates.

[0043] In some embodiments, the second phase block coordinates are determined based on the input phase coordinates and the phase block shape, the second compact space block coordinates are determined based on the input compact coordinates and the compact space block shape, and the source slot index and the target slot index are determined based on the second phase block coordinates and the second compact space block coordinates.

[0044] S104. Based on the source slot index and target slot index of the current convolutional epoch, perform convolution operation on the ciphertext corresponding to the input ciphertext index of the current convolutional epoch to obtain the output ciphertext of the current convolutional epoch, and store the output ciphertext of the current convolutional epoch in the slot corresponding to the target slot index.

[0045] In some embodiments, the slot offset can be determined based on the source slot index and the target slot index of the current convolution epoch, and at least one convolution term can be determined based on the input ciphertext index and the slot offset. Finally, a convolution operation is performed on the at least one convolution term to obtain the output ciphertext of the current convolution epoch.

[0046] In some embodiments, convolution operations can be performed directly on the slot corresponding to the target slot index, and the resulting ciphertext can be stored in the slot corresponding to the target slot index.

[0047] In other embodiments, convolution operations can be performed on the slot corresponding to the intermediate slot index to obtain intermediate ciphertext, and the intermediate ciphertext can be mapped to obtain the final output ciphertext.

[0048] By determining the input phase coordinates and input compact coordinates based on the output spatial coordinates, phase stride, and convolution parameters of the current convolution epoch, and then determining the input ciphertext index, source slot index, and target slot index based on the input phase coordinates, phase block shape, input compact coordinates, and compact spatial block shape, the ciphertext index, source slot index, and target slot index are determined. The ciphertext corresponding to the input ciphertext index is then convolved based on the source slot index and the target slot index, and the convolved output ciphertext is stored in the slot corresponding to the target slot index. This ensures that the output ciphertext directly falls into the slot corresponding to the target slot index, thereby avoiding the generation of invalid output slots and increasing the effective proportion of slots.

[0049] In some embodiments, S101 involves performing phase partitioning on the output ciphertext coordinates of the previous convolutional round based on the phase stride of the current convolutional round to obtain the phase block shape and compact spatial block shape of the current convolutional round, including: S111, the input phase step size is determined as the phase block shape.

[0050] In some embodiments, determining the phase tile shape of the current convolution epoch based on the input phase stride of the current convolution epoch can be achieved by determining the input phase stride as the phase tile shape, i.e., phase_tile_shape=Pin.

[0051] S112 performs a downward division operation on the output ciphertext coordinates and the input phase step size to obtain a compact spatial block shape.

[0052] In some embodiments, determining the compact spatial shape based on the input phase stride of the current convolutional epoch and the output ciphertext coordinates of the previous convolutional epoch can be achieved by performing a down division operation on the output ciphertext coordinates and the input phase stride to obtain the compact spatial block shape.

[0053] In some embodiments, the compact space block shape is the same as the compact space shape, that is, the input compact space block shape is the same as the input compact space shape, and the output compact space block shape is the same as the output compact space shape.

[0054] The compact spatial shape includes the input compact spatial shape (input_compact_shape) and the output compact spatial shape (output_compact_shape). In some embodiments, the input compact spatial shape is obtained by dividing the output ciphertext coordinates of the previous convolutional iteration by the input phase stride of the current convolutional iteration by a down division operation, i.e., input_compact_shape = output ciphertext coordinates of the previous convolutional iteration (input_shape) / input phase stride (Pin); the output compact spatial shape is obtained by dividing the output ciphertext coordinates of the current convolutional iteration (output_shape) by the output phase stride of the current convolutional iteration by a down division operation, i.e., output_compact_shape = output ciphertext coordinates of the current convolutional iteration (output_shape) / output phase stride of the current convolutional iteration (Pout).

[0055] Based on the above technical means, the input phase step size is determined as the phase block shape, and the output ciphertext coordinates and the input phase step size are divided downward to obtain a compact spatial block shape. This allows all slots within the same phase channel to be arranged continuously. The rotation offset corresponding to the spatial offset of the convolution kernel can be pre-calculated offline, eliminating the need for dynamic coordinate conversion during runtime. Furthermore, it prevents a tile from spanning multiple phase blocks, thus eliminating index confusion caused by crossing phase blocks.

[0056] In some embodiments, determining the input phase coordinates and input compact coordinates of the current convolutional epoch based on the output spatial coordinates of the current convolutional epoch, the phase stride of the current convolutional epoch, and the convolution parameters of the current convolutional epoch in step S102 includes: S121, based on the output spatial coordinates and the output phase step size, determines the output phase coordinates and the output compact coordinates.

[0057] In some embodiments, the above-mentioned determination of output phase coordinates and output compact coordinates based on the output spatial coordinates and phase stride of the current convolution epoch can be based on the output spatial coordinates and output phase stride to determine the output phase coordinates and output compact coordinates.

[0058] In some embodiments, determining the output phase coordinates and output compact coordinates based on the output spatial coordinates and the output phase step size can be achieved by performing mathematical operations on the output spatial coordinates and the output phase step size to obtain the output phase coordinates and output compact coordinates.

[0059] S122 performs a modulo operation on the output phase coordinates, input phase stride, and convolution parameters to obtain the input phase coordinates.

[0060] Here, mod(A, B) represents the modulo operation performed on A and B. In some embodiments, the output phase is first determined based on the output phase coordinates output_phase and the convolution parameters (conv_stride, kernel_offset, padding). The kernel offset is calculated by adding kernel_offset to padding, and then taking the modulo operation between the result and the input phase stride (input_phase_stride) to obtain the input phase coordinate (src_phase), i.e., src_phase = mod(output_phase). conv_stride+kernel_offset-padding, input_phase_stride).

[0061] S123 performs a down division operation on the output compact coordinates, the input phase step size, and the convolution parameters to obtain the input compact coordinates.

[0062] Here, floor_div(A, B) represents the downward division operation performed on A and B. In some embodiments, the operation result is first determined based on the output compact coordinates output_compact and the convolution parameters (conv_stride, kernel_offset, padding), and then the operation result and the input phase stride input_phase_stride are divided downward to obtain the input compact coordinates.

[0063] Based on the above technical means, the output phase coordinates and output compact coordinates are determined based on the output spatial coordinates and the output phase step size. Then, the modulo operation is performed on the output phase coordinates, the input phase step size, and the convolution parameters to obtain the input phase coordinates. The output compact coordinates, the input phase step size, and the convolution parameters are then divided downwards to obtain the input compact coordinates. The correct input phase subgrid can be directly traced back through the output position, realizing the mapping from output to input without the need for additional rearrangement in dense three-dimensional space.

[0064] In some embodiments, determining the output phase coordinates and output compact coordinates based on the output spatial coordinates and the output phase step size in S121 includes: S131 performs a modulo operation on the output spatial coordinates and the output phase step size to obtain the output phase coordinates.

[0065] The mathematical operations mentioned above may include modulo operations and downward division operations.

[0066] In some embodiments, the output spatial coordinates output_coord and the output phase step size Pout are moduloed to obtain the output phase coordinates output_phase, i.e., output_phase=mod(output_coord,Pout).

[0067] S132 performs a downward division operation on the output spatial coordinates and the output phase step size to obtain the output compact coordinates.

[0068] In some embodiments, the output spatial coordinates output_coord and the output phase step size Pout are divided downwards to obtain the output compact coordinates output_compact, i.e., output_compact = floor_div(output_coord, Pout).

[0069] Based on the aforementioned technical means, by performing modulo and down division operations on the output spatial coordinates relative to the output phase step size, the output spatial coordinates are decomposed into output phase coordinates and output compact coordinates. This allows for direct location of the output phase channel and its internal spatial blocks, which in turn enables further location of the input phase, achieving a mapping from output to input.

[0070] In some embodiments, the step S123 of performing a down division operation on the output compact coordinates, the input phase stride, and the convolution parameters to obtain the input compact coordinates includes: S141 performs a downward division operation on the result of the operation between the output phase coordinates and the convolution parameters, and the input phase step size to obtain the compact coordinate carry.

[0071] Among them, compact coordinate carry represents the compact coordinate cross-phase carry caused by conv_stride, kernel_offset and padding.

[0072] In some embodiments, the output phase is first determined based on the output phase coordinates (output_phase) and the convolution parameters (conv_stride, kernel_offset, padding). conv_stride + kernel_offset - padding, then divide the result of this operation by the input phase stride (input_phase_stride) to obtain the compact coordinate carry, i.e., carry = floor_div(output_phase). conv_stride+kernel_offset-padding, input_phase_stride).

[0073] S142, determine the input compact coordinates based on the sum of the output compact coordinates and the carry-over of the compact coordinates.

[0074] In some embodiments, the sum of the output compact coordinates output_compact and the compact coordinates carry is determined as the input compact coordinates input_compact, i.e., input_compact = output_compact + carry.

[0075] Based on the above technical means, the result of the operation of the output phase coordinates and convolution parameters and the input phase step size are divided downward to obtain the input compact coordinates. The input compact coordinates are determined by the sum of the output compact coordinates and the compact coordinate carry. The input compact coordinates can be directly obtained by the output compact coordinates and the compact coordinate carry. The correct input phase subgrid can be directly traced from the output position without the need for additional rearrangement in dense three-dimensional space.

[0076] In some embodiments, determining the input ciphertext index for the current convolutional epoch based on the input phase coordinates, phase block shape, input compact coordinates, and compact spatial block shape in S103 includes: S151, perform a downward division operation on the input phase coordinates and phase block shape to obtain the coordinates of the first phase block.

[0077] The first phase block coordinates may include the first input phase block coordinates `input_phase_block_coord` and the first output phase block coordinates `output_phase_block_coord`. `input_phase_block_coord` and `output_phase_block_coord` can be collectively represented as `phase_block_coord_x`, where `x` is either `in` or `out`. In some embodiments, determining the first phase block coordinates based on the input phase coordinates and the phase block shape can be achieved by performing a down division operation on the input phase coordinates `src_phase` and the phase block shape `phase_tile_shape` to obtain the first phase block coordinates. It should be noted that the first phase block coordinates used for calculation here refer to the first input phase block coordinates.

[0078] In some embodiments, the phase coordinate phase_x and the phase tile shape phase_tile_shape_x are divided downwards to obtain the first phase block coordinate phase_block_coord_x, i.e., phase_block_coord_x = floor_div(phase_x, phase_tile_shape_x).

[0079] S152, perform a downward division operation on the input compact coordinates and compact space block shape to obtain the coordinates of the first compact space block.

[0080] The first compact spatial block coordinates can include the first input compact spatial block coordinates `input_spatial_block_coord` and the first output compact spatial block coordinates `output_spatial_block_coord`. `input_spatial_block_coord` and `output_spatial_block_coord` can be collectively represented as `spatial_block_coord_x`, where x is either `in` or `out`. In some embodiments, determining the first compact spatial block coordinates based on the input compact coordinates and the compact spatial block shape can be achieved by performing a down division operation on the input compact coordinates `input_compact` and the compact spatial block shape `input_compact_tile_shape` to obtain the first compact spatial block coordinates `input_spatial_block_coord`. It should be noted that the first compact spatial block coordinates used for calculation here refer to the first input compact spatial block coordinates.

[0081] In some embodiments, the phase coordinate compact_x and the phase block shape compact_tile_shape_x are divided downwards to obtain the first phase block coordinate spatial_block_coord_x, i.e., spatial_block_coord_x = floor_div(compact_x, compact_tile_shape_x).

[0082] S153, Determine the input ciphertext index based on the first phase block coordinates and the first compact space block coordinates.

[0083] In some embodiments, the first phase block index can be determined first based on the coordinates of the first phase block, the first compact space block index can be determined based on the coordinates of the first compact space block, and the input ciphertext index can be determined based on the first phase block index and the first compact space block index.

[0084] Based on the above technical means, the first phase block coordinates and the first compact space block coordinates are obtained by separating the input phase coordinates and the phase block shape. The phase part and the compact space part are not coupled to each other, and the index logic is regular. Finally, based on the first phase block coordinates and the first compact space block coordinates, the input ciphertext index is determined, which can realize the mapping from phase to source input.

[0085] In some embodiments, determining the input ciphertext index based on the first phase block coordinates and the first compact space block coordinates in S153 includes: S161, linearize the coordinates of the first phase block and the first compact space block in the order of depth, height and width respectively to obtain the index of the first phase block and the index of the first compact space block.

[0086] In some embodiments, determining the first phase block index based on the first phase block coordinates can be achieved by linearizing the first phase block coordinates in the order of depth, height, and width to obtain the first phase block index; determining the first compact space block index based on the first compact space block coordinates can be achieved by linearizing the first compact space block coordinates in the order of depth, height, and width to obtain the first compact space block index.

[0087] Linearization in the order of depth, height, and width can be based on the linear_idx mapping, where the linear_idx mapping is linear_idx((AD,AH,AW),(aD,aH,aW))=(aD AH+aH) AW+aW.

[0088] In some embodiments, the first phase block coordinates phase_block_coord_x and the phase tile grid phase_tile_grid_x can be linearized based on the linear_idx mapping to obtain the first phase block index phase_block_idx_x, i.e., phase_block_idx_x = linear_idx(phase_tile_grid_x, phase_block_coord_x).

[0089] In some embodiments, the phase tile grid (phase_tile_grid) is determined based on the phase stride (phase_stride) and the phase tile shape (phase_tile_shape). For example, the phase tile grid (phase_tile_grid) is obtained by performing a down division operation on the phase stride (phase_stride) and the phase tile shape (phase_tile_shape), i.e., phase_tile_grid = phase_stride / phase_tile_shape.

[0090] In some embodiments, the coordinates of the first compact spatial block, spatial_block_coord_x, and the compact spatial tile grid, compact_tile_grid_x, can be linearized based on the linear_idx mapping to obtain the index of the first compact spatial block, spatial_block_idx_x, i.e., spatial_block_idx_x = linear_idx(compact_tile_grid_x, spatial_block_coord_x).

[0091] In some embodiments, the compact spatial tiled grid, compact_tile_grid, is determined based on the compact spatial shape, compact_shape, and the compact spatial tile shape, compact_tile_shape. For example, the compact spatial shape, compact_shape, and the compact spatial tile shape, compact_tile_shape, are divided downwards to obtain the compact spatial tiled grid, compact_tile_grid, i.e., compact_tile_grid = compact_shape / compact_tile_shape.

[0092] S162, perform a linear combination of the first phase block index and the first compact space block index to obtain the input ciphertext index.

[0093] In some embodiments, based on the number of compact spatial blocks (num_spatial_blocks_x) and the number of channel blocks (num_channel_blocks_x), a linear combination of the first phase block index (phase_block_idx_x) and the first compact spatial block index (spatial_block_idx_x) is performed to obtain the input ciphertext index (ct_idx_x). For example, first, the product of the first phase block index (phase_block_idx_x) and the number of compact spatial blocks (num_spatial_blocks_x) is calculated; then, the sum of this product and the first compact spatial block index (spatial_block_idx_x) is calculated; then, the product of this sum and the number of channel blocks (num_channel_blocks_x) is calculated; finally, the sum of this product and the first channel block index (channel_block_idx_x) is calculated to obtain the input ciphertext index (ct_idx_x), i.e., ct_idx_x = (phase_block_idx_x) / (spatial_block_idx_x). num_spatial_blocks_x+spatial_block_idx_x) num_channel_blocks_x+channel_block_idx_x.

[0094] In some embodiments, the number of compact spatial blocks, num_spatial_blocks_x, can be determined based on the compact spatial tile grid, compact_tile_grid_x. For example, the number of compact spatial blocks, num_spatial_blocks_x, can be obtained by multiplying the elements of the compact spatial tile grid, compact_tile_grid_x, using the multiplication function prod(), i.e., num_spatial_blocks_x = prod(compact_tile_grid_x).

[0095] In some embodiments, the number of channel blocks, num_channel_blocks_x, can be determined based on the total number of channels, Cx, and the number of channels per ciphertext, channels_per_ct_x. For example, the number of channel blocks, num_channel_blocks_x, can be obtained by rounding up the total number of channels, Cx, and the number of channels per ciphertext, channels_per_ct_x, i.e., num_channel_blocks_x = ceil(Cx / channels_per_ct_x).

[0096] In some embodiments, the first channel block index channel_block_idx_x can be determined based on the original channel index channel_x and the number of channels per ciphertext (channels_per_ct_x). For example, the first channel block index channel_block_idx_x is obtained by rounding down the original channel index channel_x and the number of channels per ciphertext (channels_per_ct_x), i.e., channel_block_idx_x = floor(channel_x / channels_per_ct_x).

[0097] Based on the above technical means, the input ciphertext index is obtained by linear combination of the first phase block, the first compact spatial block, etc., which can realize the conversion of multi-dimensional coordinates into one-dimensional input ciphertext index. The same index rule can be used on both the input and output sides, so that each layer of the network can reuse the same set of index construction logic, which facilitates the automated construction of ciphertext three-dimensional convolutional networks.

[0098] In some embodiments, determining the source slot index and target slot index of the current convolutional epoch based on the input phase coordinates, phase block shape, input compact coordinates, and compact spatial block shape in S103 includes: S171, perform a modulo operation on the input phase coordinates and phase block shape to obtain the second phase block coordinates.

[0099] The second phase block coordinates can include the second input phase block coordinates `input_local_phase_coord` and the second output phase block coordinates `output_local_phase_coord`. `input_local_phase_coord` and `output_local_phase_coord` can be collectively represented as `local_phase_coord_x`, where `x` is either `in` or `out`. In some embodiments, determining the second phase block coordinates based on the input phase coordinates and the phase tile shape can be achieved by performing a down division operation on the input phase coordinates `src_phase` and the phase tile shape `phase_tile_shape` to obtain the first phase block coordinates. It should be noted that the second phase block coordinates used for calculation here refer to the second input phase block coordinates.

[0100] In some embodiments, a modulo operation is performed on the phase coordinate phase_x and the phase tile shape phase_tile_shape_x to obtain the second phase tile coordinate local_phase_coord_x, that is, local_phase_coord_x = phase_x mod phase_tile_shape_x.

[0101] S172, perform a modulo operation on the input compact coordinates and compact space block shape to obtain the coordinates of the second compact space block.

[0102] The second compact space block coordinates can include the second input compact space block coordinates `input_local_compact_coord` and the second output compact space block coordinates `output_local_compact_coord`. `input_local_compact_coord` and `output_local_compact_coord` can be collectively represented as `local_compact_coord_x`, where x is either `in` or `out`. In some embodiments, determining the second compact space block coordinates based on the input compact coordinates and the compact space tile shape can be achieved by performing a down division operation on the input compact coordinates `input_compact` and the compact space tile shape `input_compact_tile_shape` to obtain the second compact space block coordinates `input_local_compact_coord`. It should be noted that the second compact space block coordinates used for calculation here refer to the second input compact space block coordinates.

[0103] In some embodiments, the phase coordinate compact_x and the phase block shape compact_tile_shape_x are divided downwards to obtain the first phase block coordinate local_compact_coord_x, that is, local_compact_coord_x = compact_x mod compact_tile_shape_x.

[0104] S173, based on the second phase block coordinates and the second compact space block coordinates, determine the source slot index and the target slot index.

[0105] In some embodiments, the second phase block index can be determined first based on the second phase block coordinates, the second compact space block index can be determined based on the second compact space block coordinates, and then the source slot index and the target slot index can be determined based on the second phase block index and the second compact space block index.

[0106] Based on the above technical means, the second phase block coordinates and the second compact space block coordinates are obtained by separating the input phase coordinates and the phase block shape. The phase part and the compact space part are not coupled to each other, and the index logic is regular. Finally, based on the second phase block coordinates and the second compact space block coordinates, the source slot index and the target slot index are determined, and the mapping from phase to slot index can be realized.

[0107] In some embodiments, determining the source slot index and the target slot index based on the second phase block coordinates and the second compact space block coordinates in S173 includes: S181, linearize the coordinates of the second phase block and the second compact space block in the order of depth, height and width respectively to obtain the index of the second phase block and the index of the second compact space block.

[0108] In some embodiments, the second phase block coordinates local_phase_coord_x and the phase block shape phase_tile_shape_x can be linearized based on the linear_idx mapping to obtain the second phase block index local_phase_idx_x, that is, local_phase_idx_x = linear_idx(phase_tile_shape_x, local_phase_coord_x).

[0109] In some embodiments, the second compact space block coordinates spatial_block_coord_x and compact space block shape compact_tile_shape_x can be linearized based on the linear_idx mapping to obtain the second compact space block index local_compact_idx_x, that is, local_compact_idx_x=linear_idx(compact_tile_shape_x,local_compact_coord_x).

[0110] S182 performs a product operation on the compact space block shape to obtain the total number of elements within the compact space block.

[0111] In some embodiments, the product result of multiplying the compact spatial block shapes compact_tile_shape_x is determined as the total number of elements within the compact spatial block compact_tile_size_x, i.e., compact_tile_size_x = prod(compact_tile_shape_x).

[0112] S183, based on the total number of elements in the compact space block, linearly combine the second phase block index and the second compact space block index to obtain the source slot index and the target slot index.

[0113] In some embodiments, the source slot index `input_slot` and the target slot index `output_slot` are determined by summing the product of the number of channels per ciphertext (`channels_per_ct_x`), the second phase block index `local_phase_idx_x`, and the total number of elements in the compact spatial block (`compact_tile_size_x`), and the product of the local channel index `local_channel_idx_x`, the total number of elements in the compact spatial block (`compact_tile_size_x`), and the second compact spatial block index `local_compact_idx_x`. That is, `slot_x = local_phase_idx_x`. channels_per_ct_x compact_tile_size_x+local_channel_idx_x compact_tile_size_x+local_compact_idx_x.

[0114] In some embodiments, the local channel index local_channel_idx_x can be determined based on the original channel index channel_x and the number of channels per ciphertext (channels_per_ct_x). For example, the local channel index local_channel_idx_x is obtained by performing a modulo operation on the original channel index channel_x and the number of channels per ciphertext (channels_per_ct_x), i.e., local_channel_idx_x = channel_x mod channels_per_ct_x.

[0115] Based on the above technical means, the source slot index and the target slot index are obtained by linear combination of the second phase block, the second compact spatial block, etc., which can realize the conversion of multi-dimensional coordinates into one-dimensional slot indexes. The same index rule can be used on both the input and output sides, so that each layer of the network can reuse the same set of index construction logic, which facilitates the automated construction of encrypted three-dimensional convolutional networks.

[0116] In some embodiments, in S104, based on the source slot index and target slot index of the current convolution epoch, a convolution operation is performed on the ciphertext corresponding to the input ciphertext index of the current convolution epoch to obtain the output ciphertext of the current convolution epoch, including: S191, determine the slot offset based on the difference between the source slot index and the target slot index.

[0117] In some embodiments, the above-mentioned determination of the slot offset based on the source slot index and the target slot index of the current convolution epoch can be based on the difference between the source slot index and the target slot index.

[0118] In some embodiments, the difference between the source slot index input_slot and the target slot index output_slot is determined as the slot offset delta, i.e., delta = input_slot - output_slot. This slot offset delta aligns the data in the input slot to the output slot.

[0119] S192, based on the similarity and difference between the input ciphertext index and the slot offset, determine at least one convolution term.

[0120] In some embodiments, the above-described determination of at least one convolutional term based on the input ciphertext index and slot offset may be based on the similarity or difference between the input ciphertext index and slot offset to determine at least one convolutional term.

[0121] In some embodiments, terms having the same input ciphertext index and slot offset are determined as a convolution term, i.e., InputTerm=(input_ct_idx,delta,plaintext_mask).

[0122] In some embodiments, the plaintext weight mask `plaintext_mask` is first initialized as an all-zero vector of length `n_slot`. Only when the output coordinates, output channels, input channels, and backtracked source input coordinates are all valid, and the resulting ciphertext index and slot offset belong to the current convolutional term, is `plaintext_mask[output_slot]=W[Cout,Cin,KD,KH,KW]` written to the slot corresponding to the target slot index; otherwise, the slot remains zero. Thus, the plaintext weight mask simultaneously encodes convolutional weights, padding boundaries, spatial block selection, and channel selection; multiple convolutional contributions with the same (input_ct_idx,delta) can be written to different target slots of the same mask. The last channel block allows the actual number of channels to be less than `channels_per_ct`, and slots exceeding the actual channel range remain zero.

[0123] S193, perform convolution operation on at least one convolution term based on plaintext weights to obtain the output ciphertext of the current convolution round.

[0124] The plaintext weight is the plaintext weight mask mentioned above.

[0125] In some embodiments, after performing convolution operations on at least one convolution term based on a plaintext weight mask, the convolution operation results corresponding to each of the at least one convolution term are obtained, and the convolution operation results corresponding to each of the at least one convolution term are merged into the output ciphertext, i.e., TermPlan(output_ct_idx)={InputTerm_0,InputTerm_1,...,bias}.

[0126] Based on the above technical means, at least one convolutional term is first determined based on the input ciphertext index, source slot index, and target slot index. Then, convolution operation is performed on at least one convolutional term based on plaintext weights to obtain the output ciphertext of the current convolution round. No ciphertext-ciphertext multiplication is introduced in the entire process. Usually, only the multiplication depth corresponding to one ciphertext-plaintext multiplication is consumed, so that the multiplication depth is kept within the range of linear layers.

[0127] In some embodiments, the compact spatial block shape includes an input compact spatial block shape and an output compact spatial block shape; S104, storing the output ciphertext of the current convolutional epoch in the slot corresponding to the target slot index, includes: S1001, under the condition that the preset conditions are met, the output ciphertext of the current convolution round is directly stored in the slot corresponding to the target slot index.

[0128] The preset conditions include: the input compact spatial block shape is equal to the output compact spatial block shape, i.e., input_compact_shape = output_compact_shape; the input phase stride is equal to the product of the output phase stride and the convolution stride, i.e., input_phase_stride = output_phase_stride. conv_stride; Convolution parameters include the convolution stride, which is the same as the three-dimensional convolution stride mentioned above.

[0129] In some embodiments, when input_phase_stride = output_phase_stride When conv_stride is used and input_compact_shape = output_compact_shape, a direct phase-aware output strategy is adopted. That is, starting directly from the target output_ct_idx / output_slot, the corresponding input_ct_idx / input_slot / delta is calculated in reverse, so that the rotation, plaintext weight multiplication and accumulation results fall directly into the final phase-first layout without the need for additional output rearrangement.

[0130] For example, let input_shape=(8,8,8), Pin=(4,4,4), conv_stride=(2,2,2), kernel_shape=(3,3,3), padding=(1,1,1), then output_shape=(4,4,4), Pout=(2,2,2), and input_compact_shape=output_compact_shape=(2,2,2), so a direct path can be used. Further, let n_slot=512, with input and output phase blocks of (4,4,4) and (2,2,2) respectively, and input and output compact space blocks of (2,2,2). According to the aforementioned capacity formula, input_channels_per_ct=1 and output_channels_per_ct=8. With cin=cout=0, output_coord output space coordinates=(1,0,0) and kernel_offset=(2,1,1), we can get input_coord=(3,0,0), output_slot=256, input_slot=384, delta=128. After writing W[0,0,2,1,1] into slot 256 of the plaintext weight mask, the convolution contribution directly falls into the target phase priority slot.

[0131] S1002, if the preset conditions are not met, determine the rearrangement mask based on the intermediate slot index and the target slot index of the output ciphertext, and map the output ciphertext with the intermediate slot index to the slot corresponding to the target slot index based on the rearrangement mask.

[0132] In some embodiments, when the preset conditions are not met, and a direct phase-aware output strategy is not adopted, but the output still needs to maintain the target phase-priority layout, the first stage performs convolution in the intermediate output layout; the second stage generates a rearrangement mask based on the slot positions of the same output element in the intermediate output layout and the target output layout. For example, for the same output element, its intermediate slot index in the intermediate output layout and its target slot index in the target layout are obtained, the rearrangement offset is calculated, and a 0 / 1 rearrangement mask is constructed, that is, all target positions with the same rearrangement offset are merged into the same rearrangement mask. Each rearrangement offset is traversed, and the rotation operation corresponding to the rearrangement offset is performed on the intermediate ciphertext, and plaintext multiplication is performed with the rearrangement mask corresponding to the rearrangement offset. Finally, all the ciphertext results are accumulated to obtain the final ciphertext under the target layout.

[0133] In some embodiments, the repack offset `repack_delta` is determined based on the difference between the intermediate slot index `intermediate_slot` and the target slot index `target_slot` of the output ciphertext, i.e., `repack_delta = intermediate_slot - target_slot`. A repack mask is generated based on the repack offset and the target slot index. For example, target positions with the same repack offset are merged into the same 0 / 1 repack mask, i.e., `repack_mask[repack_delta][target_slot] = 1`.

[0134] In some embodiments, mapping the output ciphertext of the intermediate slot index to the slot corresponding to the target slot index based on the rearrangement mask can be achieved by traversing each rearrangement offset, performing a ciphertext rotation operation on the intermediate ciphertext according to the rearrangement offset, multiplying the rotated ciphertext with the 0 / 1 rearrangement mask corresponding to the rearrangement offset using plaintext, and then accumulating the ciphertext obtained from each rearrangement offset operation using ciphertext addition to obtain the final output ciphertext under the target layout. The rearrangement mask sets all target slot positions corresponding to the same rearrangement offset to 1 and the remaining slot positions to 0, enabling batch processing of multiple target positions with a single rotation. This allows all target slots with the same slot offset to be merged into the same mask, and each type of slot offset only performs one rotation, instead of performing a rotation for each output point, significantly reducing the number of calls to high-overhead rotation operations.

[0135] For example, given input_shape=(8,8,8), Pin=(2,2,2), conv_stride=(1,1,1), kernel_shape=(3,3,3), padding=(0,0,0), then output_shape=(6,6,6), Pout=(2,2,2), input_compact_shape=(4,4,4), output_compact_shape=(3,3,3), which does not satisfy the condition of equal compact space shape. Therefore, a two-stage path can be used. Further, let n_slot=256, and let output_phase_tile_shape=(2,2,2), output_compact_tile_shape=(3,3,3); according to the capacity formula, output_channels_per_ct=floor(256 / (8 27))=1, therefore the complete output phase space and the complete output compact space can fit into the same output phase / spatial block. The intermediate layout of the first stage is arranged continuously according to the ordinary three-dimensional output coordinates, and the target slots of the second stage are determined according to the aforementioned phase-priority slot formula. Partial slot mapping is shown in Table 1 below: Table 1

[0136] Based on the above technical means, under the premise of meeting the preset conditions, the output ciphertext level execution plan is directly generated for the target output phase layout, so that the convolution result falls directly on the target phase-first layout without the need for additional output rearrangement. Under the premise of not meeting the preset conditions, the convolution accumulation is first completed according to the intermediate output layout that is easier to organize, and then the intermediate result is rearranged according to the target output slot mapping so that it falls into the final phase-first output layout.

[0137] The following section elaborates on the encrypted execution method for 3D stride convolution provided in the embodiments of this application, taking into account specific application scenarios.

[0138] One related technique is homomorphic 3D convolution that packages ordinary dense slots. This method directly flattens a single 3D channel into a 1D slot: slot=d H W+h W+w. When conv_stride=(1,1,1), the input and output use the same dense space expansion, and each axis uses symmetrical padding=(padding_d,padding_h,padding_w), if (KD,KH,KW) represents the convolution kernel index starting from 0, then its signed kernel offset relative to the output position is (KD-padding_d,KH-padding_h,KW-padding_w), corresponding to a fixed rotation: delta=(KD-padding_d). H W+(KH-padding_h) W+(KW-padding_w), where padding_d is the depth direction padding, padding_h is the height direction padding, and padding_w is the width direction padding. More generally, when the input and output shapes, convolution stride, or slot layout are different, the rotation offset should be calculated as delta=input_slot(input_coord)-output_slot(output_coord) based on the source input slot and the target output slot, and cannot be directly determined by the three-dimensional index of the convolution kernel alone. Then, the ciphertext convolution output is obtained through: rotate, mult_plain(weight / mask), and accumulate. This type of method can directly cover the three-dimensional convolution calculation, but its ciphertext layout is usually based on dense space unrolling. For a three-dimensional convolution with stride=(2,2,2), the ordinary dense output only retains 1 out of every 8 spatial positions, and the effective slot ratio is approximately: 1 / (2 2 2) = 1 / 8, the remaining positions need to be zeroed out by a mask or ignored subsequently. As the 3D network undergoes multi-layer downsampling, slot waste will continue to accumulate.

[0139] The second relevant scheme is a two-dimensional interleaved packing scheme, a two-dimensional sub-mesh packing scheme, or a two-dimensional non-uniform sub-network packing scheme, which will pack C H The W image or 2D feature map is divided into 2D phase or 2D subgrids, and different channels or different subgrids are mapped to CKKS slots to reduce slot waste in 2D stride convolution or high-resolution 2D image inference. This type of scheme mainly handles subgrid partitioning in both height and width directions, cross-channel spatial alignment, spatial rotation and channel rotation strategies. Its processing objects are mainly limited to 2D H / W space and do not involve phase state recursion and execution plan generation in 3D D / H / W space. Related encrypted convolution packing schemes usually focus on single-layer slot utilization, 2D spatial subgrid partitioning or ordinary channel packing, but lack layout state transition mechanisms for 3D stride convolution. For C D H In a 3D feature map, stride, padding, and kernel offset simultaneously affect the depth, height, and width spatial axes, resulting in cross-axis and cross-tile mappings between the output phase, input phase, and compact coordinates. Adding the depth dimension to 3D convolution increases the number of kernel terms from KH. KW increased to KD KH KW, space volume from H W increased to D H W. If only static subgrid layout or dense output filtering is used, problems such as mismatch between 3D phase and compact space coordinates, inability to naturally connect output phases after stride, and disruption of phase structure when large spatial feature maps cannot fit into a single ciphertext are easily encountered. Especially in 3D downsampling scenarios such as conv_stride=(2,2,2), related solutions usually cannot directly explain how the input phase stride Pin and output phase stride Pout are determined by the 3D convolution coordinate relationship, nor can they guarantee that the output layout is consistent with the real 3D convolution coordinates based on src_phase / carry mapping. In addition, when the 3D phase lane exceeds the capacity of a single CKKS ciphertext slot, if related solutions only focus on subgrid size selection, they usually cannot directly provide a fallback mechanism that maintains the 3D phase-first structure and then cuts compactspatial tiles within the same phase.

[0140] The third related approach is that when the spatial volume of a single channel is small, multiple channels can typically be sequentially packaged into the same ciphertext, or processed by blocking according to the channel dimension, to improve slot utilization. 3D convolutional kernels typically have KD... KH KW space items, for example 3 3 3 = 27, which is two-dimensional 3 Three times that of 3 convolutions. If each output channel, each output ciphertext, and each convolution kernel term is rotated independently, the number of rotations will rapidly increase, becoming the main performance bottleneck.

[0141] In summary, related technologies suffer from low effective slot utilization and significant slot waste. This application proposes a ciphertext layout and execution plan generation method driven by phase layout state transition for 3D stride convolution fully homomorphic inference (i.e., the aforementioned ciphertext execution method for 3D stride convolution). This method represents the complete ciphertext layout of the 3D input feature map as the input phase layout state Sin, where Pin only represents the input phase stride. Based on the determined model topology and 3D convolution stride chain, the output phase stride Pout is derived. Then, combined with the output shape, slot capacity, and number of output channels, output phase blocks, compact spatial blocks, and channel organization information are generated, thus forming the output phase layout state Sout. On this basis, the source input phase src_phase, compact coordinate correction carry, input / output slot mapping, plaintext weight mask, and corresponding convolution execution plan are generated according to conv_stride, kernel_offset, and padding.

[0142] 1. A phase state transition method for 3D stride convolution.

[0143] This application enables the phase stride field to recursively evolve across network layers as the stride of the 3D stride convolutional layer changes. After the model structure is determined, the system traverses backward from the model output side to the input side. For the l-th layer, the required input phase stride P(l) is determined based on its downstream output phase stride P(l+1) and the current layer's convolutional stride s(l). When there are multiple downstream branches, the phase requirements of each branch are merged axis by axis. Thus, the Pin / Pout of each layer can be derived based on the model topology and stride chain after the model is selected, without the need for enumeration and search during encrypted execution. After the phase stride is determined, the phase block, compact spatial block, and channel organization are heuristically determined based on the feature map shape and slot capacity to form a complete Sin / Sout that can be propagated between layers.

[0144] For any spatial axis, the output coordinates and the source input coordinates satisfy: input_coord = output_coord conv_stride + kernel_offset - padding. This application does not first construct the complete dense output and then filter the stride to retain the positions. Instead, it directly generates the output phase state Pout based on the input phase state Pin and the convolution stride, ensuring that the output ciphertext layout directly corresponds to the coordinate relationship after the actual 3D stride convolution. In this application, each axis of Pin must be exactly divisible by the corresponding axis of conv_stride, and satisfy: Pout = Pin / conv_stride, Pin = Pout. conv_stride. Therefore, the output layout of multi-layer 3D stride convolutions can be continuously propagated under unified phase semantics, reducing inter-layer rearrangement and invalid slots.

[0145] 2. A three-dimensional coordinate mapping and phase-priority packing method based on phase state transition.

[0146] After deriving the output phase stride Pout from the input phase stride Pin and generating the complete output layout state Sout, this application further establishes a mapping relationship between the output 3D coordinates and the source input 3D coordinates. For any output position in a 3D stride convolution, based on the output phase, convolution stride, convolution kernel offset, and padding, its corresponding source input phase and compact spatial coordinate correction can be directly determined. The core relationship can be expressed as follows: src_phase=mod(output_phase conv_stride+kernel_offset-padding, input_phase_stride).

[0147] carry = floor_div(output_phase) conv_stride+kernel_offset-padding, input_phase_stride).

[0148] input_compact=output_compact+carry.

[0149] Here, `src_phase` is used to determine the source input phase corresponding to the output position, `carry` is used to describe the compact coordinate cross-phase carry caused by stride, kernel offset, and padding, and `input_compact` is directly obtained from the output compact coordinate and this carry. Thus, the output position can be directly traced back to the correct input phase subgrid without additional rearrangement in dense 3D space.

[0150] Based on the above coordinate mapping relationship, this application adopts a phase-first packaging method to organize the three-dimensional feature map, that is, the three-dimensional space is divided according to the phase first, and then organized according to compact spatial coordinates and channels within each phase; when the three-dimensional space is large and a single phase subgrid cannot completely fit a single CKKS ciphertext, the phase-first structure is still maintained, and spatial block division is only carried out within the phase without destroying the phase layout itself.

[0151] 3. A method for generating 3D convolution execution plans based on the above layout and coordinate mapping.

[0152] After obtaining Pout, src_phase, carry, and input_compact, this application further generates the slot mapping and execution plan for 3D convolution, including the input ciphertext index input_ct_idx, the output ciphertext index output_ct_idx, the input slot, the output slot, the rotation offset delta, and the plaintext weight mask plaintext_mask. For multiple output channels that can be mapped to the same output phase / spatial tile, this application can also perform output channel fusion when the slot capacity allows.

[0153] Based on this execution plan, homomorphic 3D convolution no longer scans the dense 3D tensor point by point, but instead directly organizes effective convolution terms around the target output layout, forming the following two types of execution strategies: Direct phase-aware output strategy: This strategy directly generates an output ciphertext-level execution plan based on the target output phase layout, ensuring the convolution result falls directly on the target phase-priority layout without additional output rearrangement. Convolutional terms with the same input ciphertext index and rotation offset can be merged using the following rotation key: rotation_key = (input_ct_idx, delta). Only one ciphertext rotation is performed on the same rotation_key, and the rotation result is then reused in the plaintext multiplication and accumulation processes corresponding to multiple target output ciphertexts or multiple output channels.

[0154] Two-stage repack strategy: When the target output phase layout is not suitable for direct generation, or the conditions for achieving direct phase-aware output are not met, convolution accumulation is first performed according to the more easily organized intermediate output layout, and then the intermediate results are repacked according to the target output slot mapping so that they fall into the final phase-priority output layout.

[0155] Both strategies use the complete input / output phase layout states Sin / Sout, along with the derived src_phase, carry, and input_compact, as a unified upstream input, while maintaining consistency between the output ciphertext and the layout semantics required for the next convolutional layer. In implementation, the execution path can be selected based on the input-output phase relationship, compact spatial shape, target output layout form, and the current ciphertext level.

[0156] In summary, this application uses a combination of "3D stride convolution phase state transition + phase priority coordinate mapping and packaging + execution plan generation" to enable the output ciphertext layout to directly correspond to the real 3D stride convolution coordinate relationship, avoiding the need to construct dense output first and then filter valid positions, thereby reducing invalid slots, reducing additional rearrangement and ciphertext quantity, and suppressing the expansion of rotation overhead in 3D convolution.

[0157] This application can be integrated into a fully homomorphic encryption-based 3D convolutional model encrypted inference system, applicable to models containing Conv3D, such as medical computed tomography (CT) / magnetic resonance imaging (MRI) volumetric data analysis, video understanding models, and 3D industrial inspection models. Specifically, medical CT / MRI data analysis is used for medical image analysis; for example, CT / MRI volumetric data is encrypted and uploaded to the server, which then performs tumor segmentation or organ 3D reconstruction without accessing the original images. Video understanding models are used for behavior recognition or event detection based on encrypted video. 3D industrial inspection models are used in industrial non-destructive testing, where the server automatically identifies defects in encrypted 3D voxel data of the product. This system can be deployed using a client-side encryption, server-side encrypted inference, and client-side decryption approach, or as an offline inference process within the same trusted execution environment. Its core principle is that during model inference, each layer of 3D convolution shares the same set of phase state transition, coordinate mapping, and execution plan generation mechanisms.

[0158] See Figure 2 , Figure 2 The deployment method adopted is client-side encryption, server-side ciphertext inference, and client-side decryption. In this deployment method, the ciphertext inference process based on the fully homomorphic encryption 3D convolutional model is as follows: the client encrypts the request data (S201), the server performs ciphertext inference (S202, S2021, S2023, and S203), and the client decrypts the ciphertext inference result (S204). The detailed process is as follows: S201, the client encodes and encrypts the 3D input data into CKKS ciphertext, forming the initial input layout state corresponding to entering the first 3D stride convolutional layer.

[0159] S2011, the client generates a public-private key pair.

[0160] S2012, the client and server establish a communication connection.

[0161] S2013 uses the public key to encrypt the request data.

[0162] S2014, the client sets the server public key and sends the server public key to the server.

[0163] S202, the server loads the determined model structure parameters and plaintext weights (i.e., model parameters and model parameter encoding). Based on the model topology and the stride chain of the continuous three-dimensional stride convolutional layers, it derives the input phase stride Pin and output phase stride Pout of each layer. Then, it combines the input and output shapes, ciphertext slot capacity and number of channels to determine the phase blocks, compact spatial blocks and the number of channels carried by each ciphertext, forming the complete input / output phase layout state Sin / Sout, and generating the slot mapping, plaintext weight mask and execution plan required for each convolutional layer.

[0164] S2021, the server receives the server public key sent by the client.

[0165] S2022, the client sends a request for encrypted images to the server.

[0166] S2023, The server receives the encrypted inference request.

[0167] S203, the server executes the encrypted inference process, that is, the server executes three-dimensional convolution, bias stacking, activation and subsequent layer inference on the encrypted according to the generated execution plan. The output layout state of the previous layer can be directly used as the input layout state of the next layer to continue to be passed.

[0168] S204: After the inference is completed, the encrypted result is output, which is received by the client, decrypted, and the prediction result is obtained.

[0169] S2041, the server sends the encrypted reasoning result.

[0170] S2042, the client receives the encrypted reasoning result.

[0171] S2043, the client decrypts the ciphertext result.

[0172] The technical solution of this application can be summarized into two parts: (i) a three-dimensional phase-priority layout state and its stride-driven evolution; and (ii) a convolution term generation and execution plan based on the above layout state. The former solves how to represent the layout under three-dimensional stride convolution and how to pass it across layers, while the latter solves how to further convert the layout state into executable homomorphic convolution computation terms.

[0173] (i) Three-dimensional phase-priority layout state and its stride-driven evolution.

[0174] This application represents the complete encrypted organization of the 3D input feature map as the input phase layout state Sin, and the complete encrypted organization of the 3D output feature map as the output phase layout state Sout. In one specific implementation: Sin={Pin,input_phase_tile_shape,input_phase_tile_grid,input_compact_tile_shape,input_compact_tile_grid,input_channels_per_ct}.

[0175] Sou={Pout,output_phase_tile_shape,output_phase_tile_grid,output_compact_tile_shape,output_compact_tile_grid,output_channels_per_ct}.

[0176] Where Pin=(PD_in,PH_in,PW_in) and Pout=(PD_out,PH_out,PW_out) represent only the input and output phase step sizes, respectively; phase_tile_shape / phase_tile_grid represent the shape of the phase block carried by a single ciphertext and the block grid in the complete phase space; compact_tile_shape / compact_tile_grid represent the shape of the compact spatial block and the block grid within each phase; channels_per_ct represents the number of channels jointly carried by each ciphertext. For any spatial coordinate coord=(d,h,w) and the corresponding phase step size P=(PD,PH,PW), its three-dimensional position is decomposed into phase coordinates and compact coordinates: phase=(d mod PD, h mod PH, w mod PW).

[0177] compact=(floor(d / PD),floor(h / PH),floor(w / PW)).

[0178] Accordingly, the ciphertext is organized in the order of phase block, compact spatial tile, and channel block, so that the spatial points within the same phase subgrid are locally continuous in the slot, while different phases are separated in the layout.

[0179] Under slot capacity constraints, this application further performs joint planning of phase blocks and compact space blocks. For a single ciphertext, the following condition must be met: prod(phase_tile_shape) prod(compact_tile_shape) `channels_per_ct <= n_slot`, where the left side of the equation represents the number of phases contained in a single ciphertext, the number of compact space positions contained in each phase and each channel, and the number of channels contained in a single ciphertext, respectively. The product of these three is the number of slots required for the current layout. In some embodiments, first, `phase_tile_shape = phase_stride` and `compact_tile_shape = compact_shape`; when their product exceeds `n_slot`, the largest phase dimension greater than 1 is first divided by 2; when all phase dimensions are 1, the largest compact space dimension is then divided by 2, until a single channel's phase block and compact space block can fit a single ciphertext. Then, `channels_per_ct = floor(n_slot / (prod(phase_tile_shape))` is calculated. prod(compact_tile_shape)).

[0180] This application requires that the phase step size be divisible precisely by each axis by the phase block shape, and that the compact space shape be divisible precisely by each axis by the compact space block shape, and thus obtains: phase_tile_grid=phase_stride / phase_tile_shape.

[0181] compact_tile_grid=compact_shape / compact_tile_shape.

[0182] When a complete phase submesh cannot fit a single CKKS ciphertext, the phase-first principle is maintained, and only the phase block and the compact space block inside the phase are subdivided without breaking the phase-first organization order.

[0183] Regarding inter-layer evolution, once the model is determined, the system plans the phase stride of each feature map from the output side to the input side in reverse order based on the model topology and the 3D convolution stride chain; for feature maps with multiple downstream branches, the phase strides required by each branch are merged axis by axis. Let the current layer's 3D convolution stride be uniformly denoted as conv_stride=(SD,SH,SW), then this application requires that Pin be exactly divisible by conv_stride axis by axis, and satisfy: Pout=Pin / conv_stride.

[0184] Pin=Pout conv_stride.

[0185] Let the kernel shape be `kernel_shape`. The current Conv3DInterleavedLayer implementation does not use dilated convolution, i.e., `dilation=(1,1,1)`, and uses the same symmetrical padding on both sides of each spatial axis. Under these conditions, the actual output feature map spatial shape, the input compact spatial shape, and the output compact spatial shape are respectively: output_shape=floor((input_shape+2 padding-kernel_shape) / conv_stride)+1.

[0186] input_compact_shape=input_shape / Pin.

[0187] output_compact_shape=output_shape / Pout.

[0188] The vector multiplication, division, modulo operation, and range determination described above are all performed element-wise along the three axes of depth, height, and width. This application requires that input_shape be exactly divisible by Pin, and output_shape be exactly divisible by Pout, without using rounding up. Here, output_shape refers to the three-dimensional spatial shape of the feature map after convolution, not the convolution output value.

[0189] For any output space coordinates and kernel offset in a 3D stride convolution, the source input space coordinates satisfy: input_coord=output_coord conv_stride+kernel_offset–padding.

[0190] Wherein, input_coord / output_coord are the input space coordinates and output space coordinates, both representing three-dimensional space coordinates, not the input or output feature values; the actual output feature values ​​are obtained by the multiplication and addition of each input channel, convolution kernel offset and convolution weights, together with the bias.

[0191] Combining the decomposition relationship of phase-first layout, we can further obtain the backtracking mapping from the output position to the source input position: src_phase=mod(output_phase conv_stride+kernel_offset-padding, input_phase_stride).

[0192] carry = floor_div(output_phase) conv_stride+kernel_offset-padding, input_phase_stride).

[0193] input_compact=output_compact+carry.

[0194] Where `output_phase = mod(output_coord, Pout)`, `output_compact = floor_div(output_coord, Pout)`, `src_phase` determines the source input phase subgrid corresponding to the output position, `carry` describes the compact coordinate cross-phase carry caused by `conv_stride`, `kernel_offset`, and `padding`, and `input_compact` represents the compact coordinates obtained after decomposing the source input position according to `Pin`. `compact` is a general concept for compact coordinates; `input_compact` and `output_compact` are the specific compact coordinates on the input and output sides, respectively, while `input_compact_shape` and `output_compact_shape` are the shapes of the corresponding complete compact coordinate grids. Therefore, the output layout can be directly traced back to the correct input `phaselane` and `compacttile` without additional rearrangement in dense 3D space. For example, for the 3D phase state and phase-first ciphertext order of input shape = (4,4,4) and `Pin = (2,2,2)`, see [link to relevant documentation]. Figure 3 . Figure 3 The upper part is a three-dimensional phase unfolding diagram, with an input space of 4. 4 4 is divided into 8 phase lanes. Figure 3 The lower half is a three-dimensional phase-first ciphertext sorting. Within each phase lane, one ciphertext is written in compact coordinate order. For example, ct0 corresponds to p0=(0,0,0), ct1 corresponds to p1=(0,0,1), and so on. The three-dimensional phase states include phase0=(0,0,0), phase1=(0,0,1)…phase7=(1,1,1). The compact coordinates of phase0 include: (0,0,0), (0,0,2), (0,2,0)…(2,2,2), which correspond to the row data phase lane0.

[0195] (ii) Convolution term generation and execution plan based on the above layout state.

[0196] (1) Ciphertext and slot location.

[0197] For both the input and output sides, the side is uniformly represented by x∈{in,out}; phase_x, compact_x, and channel_x represent the phase coordinate, compact coordinate, and channel index of that side, respectively. For the input side, phase_in=src_phase, compact_in=input_compact, and channel_in=cin; for the output side, phase_out=output_phase, compact_out=output_compact, and channel_out=cout. The corresponding block coordinates and local coordinates within the block are uniformly obtained by the following formula: phase_block_coord_x=floor_div(phase_x,phase_tile_shape_x).

[0198] local_phase_coord_x=phase_x mod phase_tile_shape_x.

[0199] spatial_block_coord_x=floor_div(compact_x,compact_tile_shape_x).

[0200] local_compact_coord_x=compact_x mod compact_tile_shape_x.

[0201] channel_block_idx_x=floor(channel_x / channels_per_ct_x).

[0202] local_channel_idx_x=channel_x mod channels_per_ct_x.

[0203] In this model, both the 3D block coordinates and local coordinates are linearized in the order of depth, height, and width, with the width direction being the dimension that changes the fastest. phase_block_idx_x=linear_idx(phase_tile_grid_x,phase_block_coord_x).

[0204] spatial_block_idx_x=linear_idx(compact_tile_grid_x,spatial_block_coord_x).

[0205] local_phase_idx_x=linear_idx(phase_tile_shape_x,local_phase_coord_x).

[0206] local_compact_idx_x=linear_idx(compact_tile_shape_x,local_compact_coord_x).

[0207] Where floor_div represents the floor division method, and linear_idx((AD,AH,AW),(aD,aH,aW))=(aD AH+aH) AW+aW; the layout parameter with index x indicates that the value is taken from the corresponding Sin or Sout, for example, phase_tile_shape_in=input_phase_tile_shape, phase_tile_shape_out=output_phase_tile_shape, and C_in=Cin, C_out=Cout. Further note: num_spatial_blocks_x=prod(compact_tile_grid_x).

[0208] num_channel_blocks_x=ceil(Cx / channels_per_ct_x).

[0209] compact_tile_size_x=prod(compact_tile_shape_x).

[0210] Therefore, the same indexing rule can be used on both the input and output sides. The ciphertext index is a linear combination of phase blocks (i.e., the coordinates of the first phase block mentioned above), spatial blocks (i.e., the coordinates of the first compact spatial block mentioned above), and channel blocks, while the slot index is a linear combination of local phase (i.e., the coordinates of the second phase block mentioned above), local channel, and local compact coordinates (i.e., the coordinates of the second compact spatial block mentioned above). ct_idx_x=(phase_block_idx_x num_spatial_blocks_x+spatial_block_idx_x) num_channel_blocks_x+channel_block_idx_x.

[0211] slot_x=local_phase_idx_x channels_per_ct_x compact_tile_size_x+local_channel_idx_x compact_tile_size_x+local_compact_idx_x.

[0212] By taking x as in and out respectively, we can obtain the input_ct_idx / input_slot and output_ct_idx / output_slot used subsequently.

[0213] (2) Generation of convolution terms, rotation offsets and weight masks.

[0214] Based on the above positioning results, a rotation offset (i.e., the above slot offset amount) is generated according to "source slot minus target slot", and contributions with the same input ciphertext and rotation offset are organized into convolutional terms: delta=input_slot-output_slot.

[0215] InputTerm=(input_ct_idx,delta,plaintext_mask).

[0216] TermPlan(output_ct_idx)={InputTerm_0,InputTerm_1,...,bias}.

[0217] According to the rotation direction convention of this application, the delta can align the data in the input_slot to the output_slot; multiple convolution terms are then merged into the corresponding TermPlan according to the target output ciphertext.

[0218] The plaintext weight mask is first initialized as an all-zero vector of length n_slot. Only when the output coordinates, output channels, input channels, and backtracked source input coordinates are all valid, and the resulting ciphertext index and rotation offset belong to the current convolution term, is plaintext_mask[output_slot]=W[Cout,Cin,KD,KH,KW] written to the target slot; otherwise, the slot remains zero. Thus, the plaintext weight mask simultaneously encodes convolution weights, padding boundaries, spatial block selection, and channel selection; multiple convolutional contributions with the same (input_ct_idx,delta) can be written to different target slots of the same mask. The last channel block allows the actual number of channels to be less than channels_per_ct; slots exceeding the true channel range remain zero.

[0219] (3) Execution path selection.

[0220] The "target phase priority layout" is the final output ciphertext and slot organization method determined by the complete output state Sout. This application selects the following two types of execution paths based on the input and output layout relationship.

[0221] The first type is the direct phase-aware output strategy. When the following conditions are met: input_phase_stride=output_phase_stride conv_stride.

[0222] input_compact_shape=output_compact_shape.

[0223] The system starts directly from the target output_ct_idx / output_slot and calculates the corresponding input_ct_idx / input_slot / delta in reverse, so that the rotation, plaintext weight multiplication and accumulation results fall directly into the final phase-first layout without the need for additional output rearrangement.

[0224] The second type is the two-stage output repacking strategy. When direct phase-aware output is not used, but the output still needs to maintain the target phase-priority layout, the first stage performs convolution in the intermediate output layout; the second stage generates output based on the slot positions of the same output element in the intermediate and target layouts: repack_delta=intermediate_slot-target_slot.

[0225] repack_mask[repack_delta][target_slot]=1.

[0226] Target positions with the same repack_delta are merged into the same 0 / 1 rearrangement mask, resulting in: Cfinal=sum over repack_delta(Rotate(Cmid,repack_delta) repack_mask[repack_delta]).

[0227] Direct and Two-stage produce the same final phase-first output layout, the only difference being whether the convolution terms directly use the target slot as the accumulation position.

[0228] The following examples illustrate the slot correspondence between the two types of execution paths described above, without limiting other selectable values ​​for phase step size, block shape, number of channels, or slot capacity.

[0229] (31) Example of Direct phase-aware.

[0230] Let input_shape = (8,8,8), Pin = (4,4,4), conv_stride = (2,2,2), kernel_shape = (3,3,3), and padding = (1,1,1). Then output_shape = (4,4,4) and Pout = (2,2,2), and input_compact_shape = output_compact_shape = (2,2,2), so a Direct path can be used. Further, let n_slot = 512, with input and output phase blocks of (4,4,4) and (2,2,2) respectively, and input and output compact space blocks of (2,2,2). According to the aforementioned capacity formula, input_channels_per_ct = 1 and output_channels_per_ct = 8. Setting cin=cout=0, output_coord=(1,0,0), and kernel offset=(2,1,1), we get input_coord=(3,0,0), output_slot=256, input_slot=384, and delta=128. After writing W[0,0,2,1,1] into slot 256 of the plaintext weight mask, the convolutional contribution directly falls into the target phase-priority slot, as shown below. Figure 4 As shown.

[0231] (32) Two-stage repack example.

[0232] Let input_shape=(8,8,8), Pin=(2,2,2), conv_stride=(1,1,1), kernel_shape=(3,3,3), padding=(0,0,0), then output_shape=(6,6,6), Pout=(2,2,2), input_compact_shape=(4,4,4), output_compact_shape=(3,3,3), which does not satisfy the condition of equal compact spatial shapes for Direct, so a Two-stage path can be used. Further, let n_slot=256, and let output_phase_tile_shape=(2,2,2), output_compact_tile_shape=(3,3,3); according to the capacity formula, output_channels_per_ct=floor(256 / (8 27))=1, therefore the complete output phase space and the complete output compact space can be packed into the same output phase / spatial block. The intermediate layout of the first stage is arranged continuously according to the ordinary three-dimensional output coordinates, and the target slot of the second stage is determined according to the aforementioned phase priority slot formula.

[0233] The system merges these positions according to repack_delta, sets a rearrangement mask with a value of 1 on the corresponding target_slot, and obtains the final phase-first output layout after rotation, 0 / 1 plaintext mask multiplication and accumulation.

[0234] (4) Rotation multiplexing and ciphertext execution.

[0235] For convolutional terms with the same input ciphertext and rotation offset, they are merged using rotation_key=(input_ct_idx,delta). The same rotation key performs only one ciphertext rotation, and the rotation result can be reused for multiple plaintext weight masks, output channels, or target output ciphertexts. After accumulating all relevant convolutional terms for each output ciphertext, a rescale is performed, followed by the addition of the plaintext bias. The two-stage output rearrangement stage uses rotation, 0 / 1 plaintext mask multiplication, and accumulation, without performing additional rescale; therefore, both types of paths maintain input level L and output level L-1.

[0236] The beneficial effects of this application include: 1. Reduce slot waste in 3D stride convolution.

[0237] In a typical dense output layout, the effective output position ratio of a 3D stride convolution is: valid_ratio_dense = 1 / (SD SH Therefore, the invalid output position ratio is: invalid_ratio_dense = 1 - 1 / (SD). SH (SW). For example, when stride=(2,2,2), only 1 / 8 of the output positions are valid, while 7 / 8 are invalid. This application uses phase-priority layout and phase state transition to ensure that the output ciphertext directly corresponds to the compact coordinates after actual downsampling, thereby avoiding the generation of a large number of invalid output slots.

[0238] 2. The number of input and output ciphertexts increases in a controlled manner according to phase block, spatial tile, and channel block.

[0239] In this application, the number of input ciphertexts satisfies: num_input_ct=num_input_phase_block num_input_spatial_blocks ceil(Cin / input_channels_per_ct).

[0240] The output ciphertext satisfies: num_output_ct=num_output_phase_blocks num_output_spatial_blocks ceil(Cout / output_channels_per_ct).

[0241] Therefore, the increase in the number of ciphertexts is directly related to the actual required phase blocks, spatial blocks, and channel blocks, rather than being driven by invalid slots in the dense stride output. Even when a single ciphertext cannot accommodate a complete 3D feature map or a complete phaselane, this application can still be extended to larger 3D features through phase-first block decomposition. H W size, without disrupting phase layout semantics.

[0242] 3. Output channel fusion can quantitatively reduce the amount of output ciphertext.

[0243] Under slot capacity constraints, the number of output channels that a single output ciphertext can jointly carry is: output_channels_per_ct=floor(n_slot / (prod(output_phase_tile_shape) prod(output_compact_tile_shape))).

[0244] Without output channel fusion, the number of output ciphertexts is approximately: num_output_ct_without_fusion=num_output_phase_blocks num_output_spatial_blocks Cout.

[0245] When Cout is divisible by output_channels_per_ct, the reduction factor in the number of output ciphertexts is: reduction_factor_output_ct=output_channels_per_ct.

[0246] Therefore, output channel fusion can reduce the number of output ciphertexts proportionally to the number of fused channels without introducing additional ciphertext-ciphertext multiplication.

[0247] 4. When the direct mapping condition is met, additional output rearrangement can be avoided.

[0248] When the following layout relationship is satisfied: input_phase_stride=output_phase_stride conv_stride.

[0249] input_compact_shape=output_compact_shape.

[0250] A direct phase-aware path can be used to directly generate the output ciphertext on the target output phase layout, thus avoiding an additional output rearrangement stage. The two-stage repack path is only entered when the above direct mapping conditions are not met and the target output still needs to maintain a phase-priority layout. Therefore, this application can adaptively switch between "direct output" and "rearranged output" based on the layout relationship.

[0251] 5. The multiplication depth is kept within the range of linear layers.

[0252] The execution chain of the 3D convolutional layer in this application is: rotate, mult_plain, accumulate, rescale, add_plain(bias). No ciphertext-to-ciphertext multiplication is introduced throughout the process; typically, only the multiplication depth corresponding to one ciphertext-to-plaintext multiplication is consumed, i.e., input level L, output level L-1. Therefore, output channel fusion, rotation multiplexing, and two-stage output rearrangement do not change the fundamental depth characteristics of this layer as a plaintext-weighted linear layer.

[0253] 6. Multi-layer 3D networks can maintain end-to-end layout connectivity.

[0254] Since the layout state output by this application still maintains phase-first semantics and carries new output_phase_stride, phase block, and spatial block information, the output of the previous layer can be directly passed as the input layout state of the next layer. Therefore, continuous stride convolutions in multi-layer 3D networks do not require reconstruction of the dense layout or additional global rearrangement between layers.

[0255] This application primarily focuses on scenarios where the input phase stride (input_phase_stride) is divisible by the convolution stride (conv_stride). More generally, the initial layout of a continuous 3D stride convolutional subnetwork can be designed by considering the input space size, CKKS slot capacity, and inter-layer layout requirements. Once the initial pin is determined, the Pout of subsequent layers is still recursively obtained according to the stride-driven relationship described in this application, rather than being independently specified without the convolution stride. Therefore, the phase state transition described in this application is not limited to values ​​that are powers of 2, nor is it limited to a phase stride evolution method that reduces the phase stride by half layer by layer.

[0256] Based on this, the arrangement of slots within the ciphertext can adopt phase-continuous, channel-continuous, compact-continuous, or alternating variants thereof; spatial partitioning can adopt depth-first, height-first, width-first, three-dimensional tile, or adaptive tile; output channel fusion can also be grouped by continuous channels or by non-continuous groups according to the model structure. As long as the overall structure still maintains the basic chain of "phase-first layout state + phase internal spatial organization + channel joint organization," and can generate corresponding slot mapping, rotation offset, and plaintext mask accordingly, they all belong to the same technical concept.

[0257] This application primarily merges convolutional terms according to rotation_key=(input_ct_idx,delta). More generally, the reuse key in the execution plan can also be extended to a composite key containing information such as ciphertext level, scale, spatial block, channel block, or device execution location. As long as its essence remains the same—identifying a shareable input ciphertext rotation result and reusing that rotation result for multiple plaintext masking targets or multiple output ciphertext targets—it all belongs to the same technical concept.

[0258] Similarly, direct phase-aware output and two-stage output rearrangement are not limited to the specific implementation details in the examples of this application. Any execution plan path that first generates convolutional terms based on the layout state and then selects "directly generate target layout" or "generate intermediate layout first and then rearrange to target layout" according to the target output layout conditions can be regarded as a natural variation of the execution plan generation method of this application.

[0259] The phase-priority 3D layout state, stride-driven state transition, and execution plan generation concepts proposed in this application can be extended to other homomorphic neural network operators related to 3D spatial coordinate mapping, such as 3D average pooling and point-by-point 1... 1 1. Convolution, element-wise addition, channel concatenation, normalization, and polynomial activation, etc.

[0260] This application uses CKKS as the main example, but the above-mentioned layout state representation, phase state transition, and rotation multiplexing concepts can also be extended to other systems that support Single Instruction Multiple Data (SID). Instruction Multiple Homomorphic encryption schemes for Data (SIMD) slot operations, such as the Brakerski integer homomorphic encryption algorithm. Fan Vercauteren (BFV), hierarchical integer homomorphic encryption algorithm (Brakerski) Gentry Vaikuntanathan (BGV), etc. As long as the scheme still supports the generation of ciphertext execution plans based on slot swapping, plaintext mask multiplication, and block organization, its implementation can fall within the scope of the higher-level technology of this application.

[0261] This application provides a encrypted execution device 50 for three-dimensional stride convolution, such as... Figure 5 As shown, the encrypted execution device 50 for three-dimensional stride convolution includes...

[0262] The first determining unit 501 is used to perform phase partitioning on the output ciphertext coordinates of the previous convolutional round based on the phase stride of the current convolutional round, to obtain the phase block shape and compact spatial block shape of the current convolutional round; the phase stride includes the input phase stride and the output phase stride; the output phase stride is obtained based on the input phase stride; The second determining unit 502 is used to obtain the output space coordinates of the current convolution epoch, and determine the input phase coordinates and input compact coordinates of the current convolution epoch based on the output space coordinates of the current convolution epoch, the phase stride of the current convolution epoch, and the convolution parameters of the current convolution epoch. The third determining unit 503 is used to determine the input ciphertext index, source slot index and target slot index of the current convolutional epoch based on the input phase coordinates, phase block shape, input compact coordinates and compact spatial block shape of the current convolutional epoch. The convolution operation unit 504 is used to perform convolution operation on the ciphertext corresponding to the input ciphertext index of the current convolution epoch based on the source slot index and the target slot index of the current convolution epoch, to obtain the output ciphertext of the current convolution epoch, and to store the output ciphertext of the current convolution epoch in the slot corresponding to the target slot index.

[0263] In some embodiments, the first determining unit is further configured to determine the input phase step size as a phase block shape; and to perform a downward division operation on the output ciphertext coordinates and the input phase step size to obtain a compact spatial block shape.

[0264] In some embodiments, the second output unit is further configured to: determine output phase coordinates and output compact coordinates based on output spatial coordinates and output phase step size; perform modulo operation on output phase coordinates, input phase step size and convolution parameters to obtain input phase coordinates; and perform down division operation on output compact coordinates, input phase step size and convolution parameters to obtain input compact coordinates.

[0265] In some embodiments, the second output unit is further configured to perform a modulo operation on the output spatial coordinates and the output phase step size to obtain the output phase coordinates; and to perform a down division operation on the output spatial coordinates and the output phase step size to obtain the output compact coordinates.

[0266] In some embodiments, the second output unit is further configured to perform a downward division operation on the result of the operation between the output phase coordinates and the convolution parameters and the input phase step size to obtain the compact coordinate carry; and determine the input compact coordinates based on the sum of the output compact coordinates and the compact coordinate carry.

[0267] In some embodiments, the third output unit is further configured to: perform a downward division operation on the input phase coordinates and the phase block shape to obtain the first phase block coordinates; perform a downward division operation on the input compact coordinates and the compact space block shape to obtain the first compact space block coordinates; and determine the input ciphertext index based on the first phase block coordinates and the first compact space block coordinates.

[0268] In some embodiments, the third output unit is further configured to linearize the first phase block coordinates and the first compact space block coordinates in the order of depth, height, and width respectively to obtain the first phase block index and the first compact space block index; and to linearly combine the first phase block index and the first compact space block index to obtain the input ciphertext index.

[0269] In some embodiments, the third output unit is further configured to: perform a modulo operation on the input phase coordinates and the phase block shape to obtain the second phase block coordinates; perform a modulo operation on the input compact coordinates and the compact space block shape to obtain the second compact space block coordinates; and determine the source slot index and the target slot index based on the second phase block coordinates and the second compact space block coordinates.

[0270] In some embodiments, the third output unit is further configured to linearize the coordinates of the second phase block and the coordinates of the second compact space block in the order of depth, height and width respectively to obtain the second phase block index and the second compact space block index; perform a product operation on the compact space block shape to obtain the total number of elements in the compact space block; and perform a linear combination of the second phase block index and the second compact space block index based on the total number of elements in the compact space block to obtain the source slot index and the target slot index.

[0271] In some embodiments, the convolution operation unit is further configured to: determine the slot offset based on the difference between the source slot index and the target slot index; determine at least one convolution term based on the similarity or difference between the input ciphertext index and the slot offset; and perform a convolution operation on the at least one convolution term based on the plaintext weights to obtain the output ciphertext of the current convolution round.

[0272] In some embodiments, the compact spatial block shape includes an input compact spatial block shape and an output compact spatial block shape; the convolution operation unit is further configured to, under the condition that preset conditions are met, directly store the output ciphertext of the current convolution round in the slot corresponding to the target slot index; the preset conditions include: the input compact spatial block shape is equal to the output compact spatial block shape; the input phase stride is equal to the product of the output phase stride and the convolution stride; the convolution parameters include the convolution stride; if the preset conditions are not met, determine a rearrangement mask based on the intermediate slot index and the target slot index of the output ciphertext, and map the output ciphertext of the intermediate slot index to the slot corresponding to the target slot index based on the rearrangement mask.

[0273] It should be noted that the units included in the encrypted execution device for three-dimensional stride convolution provided in this application embodiment can be implemented by a processor in an electronic device; of course, they can also be implemented by specific logic circuits; in the implementation process, the processor can be a central processing unit (CPU), a microprocessor (MPU), a digital signal processor (DSP), or a field-programmable gate array (FPGA), etc.

[0274] The descriptions of the above device embodiments are similar to those of the above method embodiments, and have similar beneficial effects. For technical details not disclosed in the device embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.

[0275] It should be noted that, in the embodiments of this application, if the above-described encrypted execution method for three-dimensional stride convolution is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiments of this application, or the part that contributes to the related technology, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks. Thus, the embodiments of this application are not limited to any specific hardware and software combination.

[0276] This application provides an electronic device that can implement the encrypted execution device for three-dimensional stride convolution provided above.

[0277] In one example, reference Figure 6 The electronic device 60 shown includes: a processor 601, at least one communication bus 602, a user interface 603, at least one external communication interface 604, and a memory 605. The communication bus 602 is configured to enable communication between these components. The user interface 603 may include a display screen, and the external communication interface 604 may include standard wired and wireless interfaces.

[0278] The memory 605 is configured to store instructions and applications executable by the processor 601, and may also cache data to be processed or already processed by the processor 601 and various modules in the electronic device (e.g., image data, audio data, voice communication data and video communication data), and may be implemented by flash memory or random access memory (RAM).

[0279] This application provides a storage medium, namely a computer-readable storage medium, on which a computer program or instructions are stored. When the computer program or instructions are executed by a processor, they implement the steps in any of the encrypted execution methods for three-dimensional stride convolution provided in the above embodiments.

[0280] This application provides a computer program product, which includes a computer program or instructions. When the computer program or instructions are executed by a processor, they implement the steps in any of the encrypted execution methods for three-dimensional stride convolution provided in the above embodiments.

[0281] It should be noted that the descriptions of the above embodiments of storage media, devices, apparatuses, and program products are similar to the descriptions of the above method embodiments and have similar beneficial effects. For technical details not disclosed in the embodiments of storage media, devices, apparatuses, and program products of this application, please refer to the descriptions of the method embodiments of this application for understanding.

[0282] It should be understood that the phrase "one embodiment" or "an embodiment" throughout the specification means that a specific feature, structure, or characteristic related to the embodiment is included in at least one embodiment of this application. Therefore, "in one embodiment" or "in some embodiments" appearing throughout the specification do not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. It should be understood that in the various embodiments of this application, the sequence numbers of the above-described processes do not imply a sequential order of execution; the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application. The sequence numbers of the above-described embodiments are merely descriptive and do not represent the superiority or inferiority of the embodiments.

[0283] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0284] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or units can be electrical, mechanical, or other forms.

[0285] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units. They may be located in one place or distributed across multiple network units. Some or all of the units may be selected to achieve the purpose of this embodiment according to actual needs.

[0286] In addition, each functional unit in the various embodiments of this application can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in hardware or in the form of hardware plus software functional units.

[0287] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media that can store program code, such as mobile storage devices, read-only memory (ROM), magnetic disks, or optical disks.

[0288] Alternatively, if the integrated units described above are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, or the parts that contribute to related technologies, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROMs, magnetic disks, or optical disks.

[0289] The above are merely embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.

Claims

1. A method for encrypted execution of three-dimensional stride convolution, characterized in that, The method includes: Based on the phase stride of the current convolutional epoch, the output ciphertext coordinates of the previous convolutional epoch are phase-divided to obtain the phase block shape and compact spatial block shape of the current convolutional epoch; the phase stride includes the input phase stride and the output phase stride; the output phase stride is obtained based on the input phase stride; Obtain the output space coordinates of the current convolution epoch, and determine the output phase coordinates and output compact coordinates based on the output space coordinates and the output phase stride; The input phase coordinates are obtained by performing a modulo operation on the output phase coordinates, the input phase stride, and the convolution parameters of the current convolution epoch. The input compact coordinates are obtained by performing a down division operation on the output compact coordinates, the input phase stride, and the convolution parameters. Based on the input phase coordinates, phase block shape, input compact coordinates, and compact spatial block shape of the current convolutional epoch, determine the input ciphertext index, source slot index, and target slot index of the current convolutional epoch. Based on the source slot index and target slot index of the current convolution epoch, a convolution operation is performed on the ciphertext corresponding to the input ciphertext index of the current convolution epoch to obtain the output ciphertext of the current convolution epoch, and the output ciphertext of the current convolution epoch is stored in the slot corresponding to the target slot index. The step of determining the source slot index and target slot index of the current convolutional epoch based on the input phase coordinates, phase block shape, input compact coordinates, and compact spatial block shape includes: Perform a modulo operation on the input phase coordinates and the phase block shape to obtain the second phase block coordinates; Perform a modulo operation on the input compact coordinates and the compact space block shape to obtain the second compact space block coordinates; The source slot index and the target slot index are determined based on the second phase block coordinates and the second compact space block coordinates.

2. The method according to claim 1, characterized in that, The phase partitioning of the output ciphertext coordinates of the previous convolutional round based on the phase stride of the current convolutional round, to obtain the phase block shape and compact spatial block shape of the current convolutional round, includes: The input phase step size is determined as the phase block shape; The compact spatial block shape is obtained by performing a downward division operation on the output ciphertext coordinates and the input phase step size.

3. The method according to claim 1, characterized in that, The step of determining the output phase coordinates and output compact coordinates based on the output spatial coordinates and the output phase step size includes: The output phase coordinates are obtained by performing a modulo operation on the output spatial coordinates and the output phase step size. The output spatial coordinates and the output phase step size are divided downwards to obtain the output compact coordinates.

4. The method according to claim 1, characterized in that, The step of performing a down division operation on the output compact coordinates, the input phase stride, and the convolution parameters to obtain the input compact coordinates includes: The result of the operation between the output phase coordinates and the convolution parameters is divided downwards by the input phase step size to obtain compact coordinate carry-over. The input compact coordinates are determined based on the sum of the output compact coordinates and the compact coordinates with carry.

5. The method according to any one of claims 1 to 4, characterized in that, The step of determining the input ciphertext index for the current convolutional epoch based on the input phase coordinates, phase block shape, input compact coordinates, and compact spatial block shape includes: The first phase block coordinates are obtained by performing a down division operation on the input phase coordinates and the phase block shape. Perform a downward division operation on the input compact coordinates and the compact space block shape to obtain the coordinates of the first compact space block; The input ciphertext index is determined based on the first phase block coordinates and the first compact space block coordinates.

6. The method according to claim 5, characterized in that, Determining the input ciphertext index based on the first phase block coordinates and the first compact space block coordinates includes: Linearize the first phase block coordinates and the first compact space block coordinates in the order of depth, height, and width to obtain the first phase block index and the first compact space block index. The input ciphertext index is obtained by linearly combining the first phase block index and the first compact spatial block index.

7. The method according to any one of claims 1 to 4, characterized in that, Determining the source slot index and the target slot index based on the second phase block coordinates and the second compact space block coordinates includes: Linearize the second phase block coordinates and the second compact space block coordinates in the order of depth, height, and width to obtain the second phase block index and the second compact space block index. The total number of elements within the compact space block is obtained by multiplying the shapes of the compact space blocks. Based on the total number of elements within the compact space block, the second phase block index and the second compact space block index are linearly combined to obtain the source slot index and the target slot index.

8. The method according to any one of claims 1 to 4, characterized in that, The step of performing a convolution operation on the ciphertext corresponding to the input ciphertext index of the current convolution epoch based on the source slot index and the target slot index of the current convolution epoch to obtain the output ciphertext of the current convolution epoch includes: Based on the difference between the source slot index and the target slot index, the slot offset is determined; Based on the similarities and differences between the input ciphertext index and the slot offset, at least one convolutional term is determined; The at least one convolutional term is convolved based on the plaintext weights to obtain the output ciphertext of the current convolution round.

9. The method according to any one of claims 1 to 4, characterized in that, The compact spatial block shape includes an input compact spatial block shape and an output compact spatial block shape; storing the ciphertext of the current convolutional epoch in the slot corresponding to the target slot index includes: Under the condition that the preset conditions are met, the output ciphertext of the current convolution round is directly stored in the slot corresponding to the target slot index; the preset conditions include: the input compact spatial block shape is equal to the output compact spatial block shape; the input phase stride is equal to the product of the output phase stride and the convolution stride; the convolution parameters include the convolution stride; If the preset conditions are not met, a rearrangement mask is determined based on the intermediate slot index and the target slot index of the output ciphertext, and the output ciphertext of the intermediate slot index is mapped to the slot corresponding to the target slot index based on the rearrangement mask.

10. A encrypted execution device for three-dimensional stride convolution, characterized in that, The device includes: The first determining unit is used to perform phase partitioning on the output ciphertext coordinates of the previous convolutional round based on the phase stride of the current convolutional round, to obtain the phase block shape and compact spatial block shape of the current convolutional round; the phase stride includes the input phase stride and the output phase stride; the output phase stride is obtained based on the input phase stride; The second determining unit is used to obtain the output space coordinates of the current convolution epoch, and determine the output phase coordinates and output compact coordinates based on the output space coordinates and the output phase stride; perform a modulo operation on the output phase coordinates, the input phase stride and the convolution parameters of the current convolution epoch to obtain the input phase coordinates; and perform a down division operation on the output compact coordinates, the input phase stride and the convolution parameters to obtain the input compact coordinates. The third determining unit is used to determine the input ciphertext index, source slot index, and target slot index of the current convolutional epoch based on the input phase coordinates, phase block shape, input compact coordinates, and compact spatial block shape of the current convolutional epoch. The third determining unit is further configured to: perform a modulo operation on the input phase coordinates and the phase block shape to obtain the second phase block coordinates; perform a modulo operation on the input compact coordinates and the compact space block shape to obtain the second compact space block coordinates; and determine the source slot index and the target slot index based on the second phase block coordinates and the second compact space block coordinates. The convolution operation unit is used to perform convolution operation on the ciphertext corresponding to the input ciphertext index of the current convolution epoch based on the source slot index and the target slot index of the current convolution epoch, to obtain the output ciphertext of the current convolution epoch, and to store the output ciphertext of the current convolution epoch in the slot corresponding to the target slot index.

11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • System and method for data storage, transfer, synchronization, and security

    US20190129640A1

  • Millimeter-wave wide beam DRA and design method therefor, and wide-angle beam scanning phased array and design method therefor

    WO2024229985A1