VSCode之C++ CUDA入门:reduce的N+1重境界

  1. 背景
    Reduce是几乎所有多线程技术的基础和关键,同样也是诸如深度学习等领域的核心,简单如卷积运算,复杂如梯度聚合、分布式训练等,了解CUDA实现reduce,以及优化reduce是理解CUDA软硬件连接点的很好切入点。

硬件环境:
在这里插入图片描述

  1. 结果展示
chapter2 reduce test
sum of 16777216 random nums, host: 8389334.731, 18.6554 ms, GPU 0: 8389334.000, 4.3356 ms 
sum of 16777216 random nums, host: 8389334.731, 18.6554 ms, GPU 1: 8389335.000, 1.3475 ms 
sum of 16777216 random nums, host: 8389334.731, 18.6554 ms, GPU 2: 8389335.000, 1.3096 ms 
sum of 16777216 random nums, host: 8389334.731, 18.6554 ms, GPU 3: 8389335.000, 1.3098 ms 
sum of 16777216 random nums, host: 8389334.731, 18.6554 ms, GPU 4: 8389335.000, 1.3093 ms 
sum of 16777216 random nums, host: 8389334.731, 18.6554 ms, GPU 5: 8389335.000, 1.3119 ms 
sum of 16777216 random nums, host: 8389334.731, 18.6554 ms, GPU 6: 8389335.000, 1.3132 ms 
sum of 16777216 random nums, host: 8389334.731, 18.6554 ms, GPU 7: 8389335.000, 1.3157 ms 
sum of 16777216 random nums, host: 8389334.731, 18.6554 ms, L1 v7: 8389335.000, 1.3086 ms 
sum of 16777216 random nums, host: 8389334.731, 18.6554 ms, L1 Co: 8389335.000, 2.6103 ms 
sum of 16777216 random nums, host: 8389334.731, 18.6554 ms, L any: 8389335.000, 1.6096 ms 
sum of 16777216 random nums, host: 8389334.731, 18.6554 ms, GPU 8: 8389335.000, 1.3160 ms 
  1. 源码
#include"../include/utils/cx.h"
#include"../include/utils/cxtimers.h"
#include"cooperative_groups.h" // for cg namespace
#include"cooperative_groups/reduce.h" // for cg::reduce
#include"../include/utils/helper_math.h" // for overload += operator for reinterpret (CYDA SDK)
#include<random>namespace cg = cooperative_groups;__global__ void reduce0(float* x, int n) {int tid = blockDim.x * blockIdx.x + threadIdx.x;x[tid] += x[tid+n];
}__global__ void reduce1(float *x,int N)
{int tid = blockDim.x*blockIdx.x+threadIdx.x;float tsum = 0.0f;int stride = gridDim.x*blockDim.x;for(int k=tid; k<N; k += stride) tsum += x[k];x[tid] = tsum;
}__global__ void reduce2(float *y,float *x,int N)
{extern __shared__ float tsum[]; // Dynamically Allocated Shared Memint id = threadIdx.x;int tid = blockDim.x*blockIdx.x+threadIdx.x;int stride = gridDim.x*blockDim.x;tsum[id] = 0.0f;for(int k=tid;k<N;k+=stride) tsum[id] += x[k];__syncthreads();for(int k=blockDim.x/2; k>0; k /= 2){ // power of 2 reduction loopif(id<k) tsum[id] += tsum[id+k];__syncthreads();}if(id==0) y[blockIdx.x] = tsum[0]; // store one value per block
}__global__ void reduce3(float *y,float *x,int N)
{extern __shared__ float tsum[];int id = threadIdx.x;int tid = blockDim.x*blockIdx.x+threadIdx.x;int stride = gridDim.x*blockDim.x;tsum[id] = 0.0f;for(int k=tid;k<N;k+=stride) tsum[id] += x[k];__syncthreads();int block2 = cx::pow2ceil(blockDim.x); // next higher power of 2for(int k=block2/2; k>0; k >>= 1){     // power of 2 reduction loopif(id<k && id+k < blockDim.x) tsum[id] += tsum[id+k];__syncthreads();}if(id==0) y[blockIdx.x] = tsum[0]; // store one value per block
}__global__ void reduce4(float * y,float * x,int N)
{extern __shared__ float tsum[];int id = threadIdx.x;int tid = blockDim.x*blockIdx.x+threadIdx.x;int stride = gridDim.x*blockDim.x;tsum[id] = 0.0f;for(int k=tid;k<N;k+=stride) tsum[id] += x[k];__syncthreads();if(id<256 && id+256 < blockDim.x) tsum[id] += tsum[id+256]; __syncthreads();if(id<128) tsum[id] += tsum[id+128]; __syncthreads();if(id< 64) tsum[id] += tsum[id+ 64]; __syncthreads();if(id< 32) tsum[id] += tsum[id+ 32]; __syncthreads();// warp 0 only from hereif(id< 16) tsum[id] += tsum[id+16]; __syncwarp();if(id< 8)  tsum[id] += tsum[id+ 8]; __syncwarp();if(id< 4)  tsum[id] += tsum[id+ 4]; __syncwarp();if(id< 2)  tsum[id] += tsum[id+ 2]; __syncwarp();if(id==0)  y[blockIdx.x] = tsum[0]+tsum[1];
}template <int blockSize>
__global__ void reduce5(r_Ptr<float> sums,cr_Ptr<float> data,int n)
{// This template kernel assumes that blockDim.x = blockSize, // that blockSize is power of 2 between 64 and 1024 __shared__ float s[blockSize];int id = threadIdx.x;       // rank in block   s[id] = 0;for(int tid = blockSize*blockIdx.x+threadIdx.x;tid < n; tid += blockSize*gridDim.x) s[id] += data[tid];__syncthreads();if(blockSize > 512 && id < 512 && id+512 < blockSize)s[id] += s[id+512];__syncthreads();if(blockSize > 256 && id < 256 && id+256 < blockSize)s[id] += s[id+256];__syncthreads();if(blockSize > 128 && id < 128 && id+128 < blockSize)s[id] += s[id+128];__syncthreads();if(blockSize >  64 && id <  64 && id+ 64 < blockSize)s[id] += s[id+64];__syncthreads();if(id < 32) {  //  single warp from heres[id]             += s[id + 32]; __syncwarp(); // the syncwarpsif(id < 16) s[id] += s[id + 16]; __syncwarp(); // are requiredif(id <  8) s[id] += s[id +  8]; __syncwarp(); // for devices ofif(id <  4) s[id] += s[id +  4]; __syncwarp(); // CC = 7 and aboveif(id <  2) s[id] += s[id +  2]; __syncwarp(); // for CC < 7if(id <  1) s[id] += s[id +  1]; __syncwarp(); // they do nothingif(id == 0) sums[blockIdx.x] = s[0]; // store block sum}
}
// using warp_shrl functions
template<int blockSize>
__global__ void reduce6(r_Ptr<float> sums, cr_Ptr<float> data, int n) {__shared__ float s[blockSize];auto grid = cg::this_grid();auto block = cg::this_thread_block();auto warp = cg::tiled_partition<32>(block);int id = block.thread_rank();s[id] = 0.0f;for (int tid = grid.thread_rank(); tid < n; tid += grid.size()) {s[id] += data[tid];}block.sync();if (blockSize > 512 && id < 512 && id + 512 < blockSize) {s[id] += s[id + 512];}block.sync();if (blockSize > 256 && id < 256 && id + 256 < blockSize) {s[id] += s[id+256];}block.sync();if (blockSize > 128 && id < 128 && id + 128 < blockSize) {s[id] += s[id+128];}block.sync();if (blockSize > 64 && id < 64 && id + 64 < blockSize) {s[id] += s[id+64];}block.sync();if (warp.meta_group_rank() == 0) {s[id] += s[id+32];warp.sync();s[id] += warp.shfl_down(s[id], 16);s[id] += warp.shfl_down(s[id], 8);s[id] += warp.shfl_down(s[id], 4);s[id] += warp.shfl_down(s[id], 2);s[id] += warp.shfl_down(s[id], 1);if (id == 0){sums[blockIdx.x] = s[0];}}
}// warp-only reduce function
__global__ void reduce7(r_Ptr<float> sums,cr_Ptr<float> data,int n)
{// This kernel assumes the array sums is set to zeros on entry// also blockSize is multiple of 32 (should always be true)auto grid =  cg::this_grid();auto block = cg::this_thread_block();auto warp =  cg::tiled_partition<32>(block);float v = 0.0f;  // accumulate thread sums in register variable vfor(int tid=grid.thread_rank(); tid<n; tid+=grid.size()) v += data[tid];warp.sync();v += warp.shfl_down(v,16); // | v += warp.shfl_down(v,8);  // | warp levelv += warp.shfl_down(v,4);  // | reduce herev += warp.shfl_down(v,2);  // |v += warp.shfl_down(v,1);  // | //  use atomicAdd here to sum over warpsif(warp.thread_rank()==0) atomicAdd(&sums[block.group_index().x],v);
}// warp-only and L1 cache function
__global__ void reduce7_L1(r_Ptr<float> sums, cr_Ptr<float> data, int n) {auto grid = cg::this_grid();auto block = cg::this_thread_block();auto warp = cg::tiled_partition<32>(block);float4 v4 = {0.0f, 0.0f, 0.0f, 0.0f};for(int tid = grid.thread_rank(); tid < n/4; tid += grid.size()) {v4 += reinterpret_cast<const float4 *>(data)[tid];}float v = v4.x + v4.y + v4.z + v4.w;warp.sync();v += warp.shfl_down(v, 16);v += warp.shfl_down(v, 8);v += warp.shfl_down(v, 4);v += warp.shfl_down(v, 2);v += warp.shfl_down(v, 1);if (warp.thread_rank() == 0){atomicAdd(&sums[block.group_index().x], v);}
}__device__ void reduce7_L1_coal(r_Ptr<float>sums,cr_Ptr<float>data,int n)
{// This function assumes that a.size() is power of 2 in [1,32]// and that n is a multiple of 4auto g = cg::this_grid();auto b = cg::this_thread_block();auto a = cg::coalesced_threads(); // active threads in warpfloat4 v4 ={0,0,0,0};for(int tid = g.thread_rank(); tid < n/4; tid += g.size())v4 += reinterpret_cast<const float4 *>(data)[tid];float v = v4.x + v4.y + v4.z + v4.w;a.sync();if(a.size() > 16) v += a.shfl_down(v,16); // NB no newif(a.size() >  8) v += a.shfl_down(v,8);  // thread if(a.size() >  4) v += a.shfl_down(v,4);  // divergenceif(a.size() >  2) v += a.shfl_down(v,2);  // allowedif(a.size() >  1) v += a.shfl_down(v,1);  // here               // rank here is within coal group therefore if(a.thread_rank() == 0) atomicAdd(&sums[b.group_index().x],v); // rank==0 OK even for odd only threads
}__global__ void reduce7_coal_even_odd(r_Ptr<float>sumeven,r_Ptr<float>sumodd,cr_Ptr<float>data,int n)
{// divergent code hereif(threadIdx.x%2==0) reduce7_L1_coal(sumeven,data,n);else                 reduce7_L1_coal(sumodd,data,n);
}// reduce L1 coal any
__device__ void reduce7_L1_coal_any(r_Ptr<float>sums,cr_Ptr<float>data,int n)
{// This function works for any value of a.size() in [1,32] // it assumes that n is a multiple of 4auto g = cg::this_grid();auto b = cg::this_thread_block();auto w = cg::tiled_partition<32>(b); // whole warpauto a = cg::coalesced_threads();    // active threads in warpint warps = g.group_dim().x*w.meta_group_size(); // number of warps in grid// divide data into contiguous parts, with one part per warp int part_size = ((n/4)+warps-1)/warps;int part_start = (b.group_index().x*w.meta_group_size() +w.meta_group_rank())*part_size;int part_end = min(part_start+part_size,n/4);// get part sub-sums into threads of afloat4 v4 ={0,0,0,0};int id = a.thread_rank();for(int k=part_start+id; k<part_end; k+=a.size()) // adjacent adds withinv4 += reinterpret_cast<const float4 *>(data)[k]; //    the warpfloat v = v4.x + v4.y + v4.z + v4.w;a.sync();// now reduce over a// first deal with items held by ranks >= kstartint kstart = 1 << (31 - __clz(a.size())); // max power of 2 <= a.size()if(a.size() > kstart) {float w = a.shfl_down(v,kstart);if(a.thread_rank() < a.size()-kstart) v += w;// only update v for         a.sync();                                    // valid low ranking threads}// then do power of 2 reductionfor(int k = kstart/2; k>0; k /= 2) v += a.shfl_down(v,k);if(a.thread_rank() == 0) atomicAdd(&sums[b.group_index().x],v);
}__global__ void reduce7_any(r_Ptr<float>sums,cr_Ptr<float>data,int n)
{if(threadIdx.x % 3 == 0)  reduce7_L1_coal_any(sums,data,n);
}// cg warp-level function
__global__ void reduce8(r_Ptr<float> sums, cr_Ptr<float> data, int n) {auto grid = cg::this_grid();auto block = cg::this_thread_block();auto warp = cg::tiled_partition<32>(block);float v = 0.0f;for(int tid = grid.thread_rank(); tid < n; tid += grid.size()) {v += data[tid];}v = cg::reduce(warp, v, cg::plus<float>());warp.sync();if (warp.thread_rank() == 0) {atomicAdd(&sums[block.group_index().x], v);}
}void test_reduce(const int N) {// const int N = 1 << 24;const int blocks = 256;const int threads = 256;const int nreps = 1000;thrust::host_vector<float> x(N);thrust::device_vector<float> dx(N);// init datastd::default_random_engine gen(42);std::uniform_real_distribution<float> fran(0.0, 1.0);for (int k = 0; k < N; k++) {x[k] = fran(gen);}// host to devicedx = x;cx::timer tim;// cpu time testdouble host_sum = 0.0;for (int k = 0; k < N; k++) {host_sum += x[k];}double t1 = tim.lap_ms();// gpu test reduce0double gpu_sum = 0.0;tim.reset();for (int m = N/2; m > 0; m /= 2) {int threads = std::min(256, m);int blocks = std::max(m / 256, 1);reduce0<<<blocks, threads>>> (dx.data().get(), m);}cudaDeviceSynchronize();double t2 = tim.lap_ms();// device to hostgpu_sum = dx[0];printf("sum of %d random nums, host: %.3f, %.4f ms, GPU 0: %.3f, %.4f ms \n", N, host_sum, t1, gpu_sum, t2);// gpu test reduce1dx = x;tim.reset();for (int rep = 0; rep < nreps; rep++) {reduce1<<<blocks, threads>>> (dx.data().get(), N);reduce1<<<1, threads>>> (dx.data().get(), blocks * threads);reduce1<<<1, 1>>> (dx.data().get(), threads);if (rep == 0) gpu_sum = dx[0];}cudaDeviceSynchronize();double t3 = tim.lap_ms() / nreps;printf("sum of %d random nums, host: %.3f, %.4f ms, GPU 1: %.3f, %.4f ms \n", N, host_sum, t1, gpu_sum, t3);// gpu test reduce2dx = x;thrust::device_vector<float> dy(blocks);tim.reset();for (int rep = 0; rep < nreps; rep++) {reduce2<<<blocks, threads, threads * sizeof(float)>>> (dy.data().get(), dx.data().get(), N);reduce2<<<1, threads, blocks * sizeof(float)>>> (dx.data().get(), dy.data().get(), blocks);if (rep == 0) gpu_sum = dx[0];}cudaDeviceSynchronize();double t4 = tim.lap_ms() / nreps;printf("sum of %d random nums, host: %.3f, %.4f ms, GPU 2: %.3f, %.4f ms \n", N, host_sum, t1, gpu_sum, t4);// gpu test reduce3dx = x;tim.reset();for (int rep = 0; rep < nreps; rep++) {reduce3<<<blocks, threads, threads * sizeof(float)>>> (dy.data().get(), dx.data().get(), N);reduce3<<<1, threads, blocks * sizeof(float)>>> (dx.data().get(), dy.data().get(), blocks);if (rep == 0) gpu_sum = dx[0];}cudaDeviceSynchronize();double t5 = tim.lap_ms() / nreps;printf("sum of %d random nums, host: %.3f, %.4f ms, GPU 3: %.3f, %.4f ms \n", N, host_sum, t1, gpu_sum, t5);// gpu test reduce4dx = x;tim.reset();for (int rep = 0; rep < nreps; rep++) {reduce4<<<blocks, threads, threads * sizeof(float)>>> (dy.data().get(), dx.data().get(), N);reduce4<<<1, threads, blocks * sizeof(float)>>> (dx.data().get(), dy.data().get(), blocks);if (rep == 0) gpu_sum = dx[0];}cudaDeviceSynchronize();double t6 = tim.lap_ms() / nreps;printf("sum of %d random nums, host: %.3f, %.4f ms, GPU 4: %.3f, %.4f ms \n", N, host_sum, t1, gpu_sum, t6);// gpu test reduce5dx = x;tim.reset();for (int rep = 0; rep < nreps; rep++) {reduce5<256><<<blocks,threads,threads*sizeof(float)>>>(dy.data().get(),dx.data().get(),N);}reduce4<<<1, blocks, blocks*sizeof(float)>>>(dx.data().get(), dy.data().get(), blocks);cudaDeviceSynchronize();double t7 = tim.lap_ms() / nreps;gpu_sum = dx[0];printf("sum of %d random nums, host: %.3f, %.4f ms, GPU 5: %.3f, %.4f ms \n", N, host_sum, t1, gpu_sum, t7);// gpu tst reduce6dx = x;tim.reset();for (int rep = 0; rep < nreps; rep++) {reduce6<256><<<blocks, threads, threads*sizeof(float)>>>(dy.data().get(), dx.data().get(), N);}reduce4<<<1, blocks, blocks*sizeof(float)>>>(dx.data().get(), dy.data().get(), blocks);cudaDeviceSynchronize();double t8 = tim.lap_ms() / nreps;gpu_sum = dx[0];printf("sum of %d random nums, host: %.3f, %.4f ms, GPU 6: %.3f, %.4f ms \n", N, host_sum, t1, gpu_sum, t8);// gpu test reduce7dx = x;thrust::device_vector<float> dz(blocks);tim.reset();for (int rep = 0; rep < nreps; rep++) {reduce7<<<blocks, threads, threads*sizeof(float)>>>(dz.data().get(), dx.data().get(), N);reduce7<<<1, blocks, blocks*sizeof(float)>>>(dx.data().get(), dz.data().get(), blocks);if (rep == 0) gpu_sum = dx[0];}cudaDeviceSynchronize();double t9 = tim.lap_ms() / nreps;printf("sum of %d random nums, host: %.3f, %.4f ms, GPU 7: %.3f, %.4f ms \n", N, host_sum, t1, gpu_sum, t9);// gpu test reduce7_L1dx = x;thrust::fill(dz.begin(), dz.end(), 0.0);tim.reset();for (int rep = 0; rep < nreps; rep++) {reduce7_L1<<<blocks, threads, threads*sizeof(float)>>>(dz.data().get(), dx.data().get(), N);reduce7_L1<<<1, blocks, blocks*sizeof(float)>>>(dx.data().get(), dz.data().get(), blocks);if (rep == 0) gpu_sum = dx[0];}cudaDeviceSynchronize();double t91 = tim.lap_ms() / nreps;printf("sum of %d random nums, host: %.3f, %.4f ms, L1 v7: %.3f, %.4f ms \n", N, host_sum, t1, gpu_sum, t91);// gpu test reduce7_L1 coalthrust::device_vector<float>  dy_even(blocks);  // only even elements are usedthrust::device_vector<float>  dy_odd(blocks);   // only odd elements are useddx = x;tim.reset();for(int rep=0;rep<nreps;rep++){reduce7_coal_even_odd<<<blocks,threads>>>(dy_even.data().get(),dy_odd.data().get(),dx.data().get(),N);if (rep == 0) {// use reduce7_L1 for final step// dx[0] = 0.0f; // clear output bufferreduce7_L1<<<1,blocks>>>(dx.data().get(),dy_even.data().get(),blocks);reduce7_L1<<<1,blocks>>>(dx.data().get(),dy_odd.data().get(),blocks);gpu_sum  = dx[0];}}cudaDeviceSynchronize();double t92 = tim.lap_ms()/nreps;// gpu_sum  = dx[0];  // D2H copy (1 word)printf("sum of %d random nums, host: %.3f, %.4f ms, L1 Co: %.3f, %.4f ms \n", N, host_sum, t1, gpu_sum, t92);// gpu test reduce 7 L1 coal anydx = x;thrust::fill(dy.begin(), dy.end(), 0.0);tim.reset();for(int rep=0;rep<nreps;rep++){reduce7_any<<<blocks,threads>>>(dy.data().get(),dx.data().get(),N);if (rep == 0) {reduce7_L1<<<1,blocks>>>(dx.data().get(),dy.data().get(),blocks);gpu_sum = dx[0];}}cudaDeviceSynchronize();double t93 = tim.lap_ms() / nreps;printf("sum of %d random nums, host: %.3f, %.4f ms, L any: %.3f, %.4f ms \n", N, host_sum, t1, gpu_sum, t93);// gpu test reduce8dx = x;thrust::fill(dy.begin(), dy.end(), 0.0);tim.reset();for (int rep = 0; rep < nreps; rep++) {reduce8<<<blocks, threads, threads*sizeof(float)>>>(dy.data().get(), dx.data().get(), N);reduce8<<<1, blocks, blocks*sizeof(float)>>>(dx.data().get(), dy.data().get(), blocks);if (rep == 0) gpu_sum = dx[0];}cudaDeviceSynchronize();double t10 = tim.lap_ms() / nreps;printf("sum of %d random nums, host: %.3f, %.4f ms, GPU 8: %.3f, %.4f ms \n", N, host_sum, t1, gpu_sum, t10);
}
  1. 小结
    1)尝试了9+1中CUDA中最基本的reduce方法,从基本方法到高级库,从精度和速度两方面进行的对比,可以看到与CPU的reduce算法相比,GPU算法明显快很多,更好的显卡,速度应该会更快,同时要注意部分精度损失,这也是CUDA编程中应注意到是否在误差允许范围内;
    2)理论上reduce7_L1_coal应该比reduce7_L1,reduce7速度更快,实测本地电脑测试反而更慢了,猜测原因可能是机器的GPU性能受限导致的;
    3)以上测试结果在不同机子上的总体趋势较一致,细微有差别,与GPU的架构、block\threads的数量、数据计算的总量等都有关系,实际应用中可能需要进一步微调。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/203428.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

HarmonyOS4.0从零开始的开发教程03初识ArkTS开发语言(中)

HarmonyOS&#xff08;二&#xff09;初识ArkTS开发语言&#xff08;中&#xff09;之TypeScript入门 浅析ArkTS的起源和演进 1 引言 Mozilla创造了JS&#xff0c;Microsoft创建了TS&#xff0c;Huawei进一步推出了ArkTS。 从最初的基础的逻辑交互能力&#xff0c;到具备类…

http和https的区别有哪些

目录 HTTP&#xff08;HyperText Transfer Protocol&#xff09; HTTPS&#xff08;HyperText Transfer Protocol Secure&#xff09; 区别与优势 应用场景 未来趋势 当我们浏览互联网时&#xff0c;我们经常听到两个常用的协议&#xff1a;HTTP&#xff08;HyperText Tra…

Excel 动态拼接表头实现导出

public class Column {//单元格内容private String content;//字段名称&#xff0c;用户导出表格时反射调用private String fieldName;//这个单元格的集合private List<Column> listTpamscolumn new ArrayList<Column>();int totalRow;int totalCol;int row;//exc…

易宝OA 两处任意文件上传漏洞复现

0x01 产品简介 易宝OA系统是一种专门为企业和机构的日常办公工作提供服务的综合性软件平台,具有信息管理、 流程管理 、知识管理(档案和业务管理)、协同办公等多种功能。 0x02 漏洞概述 易宝OA系统UploadFile、BasicService.asmx等接口处存在文件上传漏洞,未授权的攻击者可…

记录 | vscode pyhton c++调试launch.json配置

下面提供 vscode 中 python 和 c 调试配置的 launch.json (好用&#xff0c;已用好几年&#xff0c;建议收藏) {// 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。// 欲了解更多信息&#xff0c;请访问: https://go.microsoft.com/fwlink/?linkid830387&qu…

【Spring】依赖注入之属性注入详解

前言&#xff1a; 我们在进行web开发时&#xff0c;基本上一个接口对应一个实现类&#xff0c;比如IOrderService接口对应一个OrderServiceImpl实现类&#xff0c;给OrderServiceImpl标注Service注解后&#xff0c;Spring在启动时就会将其注册成bean进行统一管理。在Co…

WireShark监控浏览器登录过程网络请求

软件开发中经常前后端扯皮。一种是用Chrome浏览器的开发者工具 来看网络交互&#xff0c;但是前提是 网络端口的确是通的。 WireShark工作在更低层。 这个工具最大的好处&#xff0c;大家别扯皮&#xff0c;看网络底层的log&#xff0c;到底 你的端口开没开&#xff0c; 数据…

计算机图形图像技术(OpenCV核心功能、图像变换与图像平滑处理)

一、实验原理&#xff1a; 1、显示图像 void imshow(const string &name, InputArray image); ①功能&#xff1a;在指定窗口中显示图像。 ②参数&#xff1a;name为窗口的名字&#xff1b;image为待显示的图像。 ③说明&#xff1a;可显示彩色或灰度的字节图像和浮点数图…

C++ 中的运算符重载(三)

重载加法运算符和减法运算符-&#xff0c;用于实现对象的加法和减法。加法运算符和减法运算符-是两种常用的运算符&#xff0c;它们可以对两个操作数进行加法和减法运算&#xff0c;返回一个运算结果。但是&#xff0c;如果我们想要对自定义类型的数据进行加法和减法运算&#…

Threejs项目实战之一:汽车外观换肤效果三维展示

目录 最终效果1 创建项目2 安装插件3 编写代码3.1 准备工作3.2 代码编写3.2.1 在template标签中构建html页面3.2.2 在style标签中构建页面样式文件3.2.3 在script标签中编写js代码 最终效果 先看下最终实现的效果 接下来&#xff0c;我们就从创建项目开始&#xff0c;一步一步…

RDMA编程实例rdma_cm API

RDMA编程基础 存储大师班 | RDMA简介与编程基础 -https://zhuanlan.zhihu.com/p/387549948 1. RDMA的学习环境搭建 RDMA需要专门的RDMA网卡或者InfiniBand卡才能使用&#xff0c;学习RDMA而又没有这些硬件设备&#xff0c;可以使用一个软件RDMA模拟环境&#xff0c;softiwarp …

【软考】局部性原理

目录 一、说明二、类型2.1 时间局部性2.2 空间局限性2.3顺序局部性 一、说明 1.局部性原理是指CPU访问存储器时&#xff0c;无论是存取指令还是存取数据&#xff0c;所访问的存储单元都趋于聚集在一个较小的连续区域中。 二、类型 2.1 时间局部性 1.Temporal Locality 2.如果…

自主并不等于智能

自主不等于智能&#xff0c;也不是自动化的简单升级。自主性和智能性是两个不同的概念。自主性指物体或系统具有独立决策和行动的能力&#xff0c;不需要人为干预。而智能性指物体或系统具有类似人类的智慧、学习和适应能力。 虽然自主性通常与智能性相关&#xff0c;但并非所有…

李宏毅bert记录

一、自监督学习&#xff08;Self-supervised Learning&#xff09; 在监督学习中&#xff0c;模型的输入为x&#xff0c;若期望输出是y&#xff0c;则在训练的时候需要给模型的期望输出y以判断其误差——有输入和输出标签才能训练监督学习的模型。 自监督学习在没有标注的训练…

【后端】JVM 远程调试

前言 再好的代码,也还是有瑕疵的,不是代码不给力,是线上问题太牛逼太玄幻。这不刚部署就出现了问题,幸好还是测试的时候,早点发现早点解决,不给任何人带来不必要的损失,是我做人的原则,只要钱到位,任何问题都不是问题。 JVM 远程调试 不得不说 IDEA 和 宝塔配合是真…

工厂方法设计模式项目实践

前言 以采集数据处理逻辑为例&#xff0c;数据采集分为不同种类如&#xff1a;MQTT、MODBUS、HTTP等&#xff0c;不同的采集数据有不同的解析处理逻辑。但总体解析处理步骤是固定的。可以使用工厂方法设计模式简化代码&#xff0c;让代码变得更加优雅。 代码实战 抽象类 总体…

gpt3、gpt2与gpt1区别

参考&#xff1a;深度学习&#xff1a;GPT1、GPT2、GPT-3_HanZee的博客-CSDN博客 Zero-shot Learning / One-shot Learning-CSDN博客 Zero-shot&#xff08;零次学习&#xff09;简介-CSDN博客 GPT-2 模型由多层单向transformer的解码器部分构成&#xff0c;本质上是自回归模型…

10_企业架构NOSQL数据库之MongoDB

企业架构NOSQL数据库之MongoDB 学习目标和内容 1、能够简单描述MongoDB的使用特点 2、能够安装配置启动MongoDB 3、能够使用命令行客户端简单操作MongoDB 4、能够实现基本的数据操作 5、能够实现MongoDB基本安全设置 6、能够操作安装php的MongoDB扩展 一、背景描述及其方案设计…

Vue实战(十):对数组数据的拆分和分组合并

Vue实战&#xff08;十&#xff09;&#xff1a;对数组数据的拆分和分组合并 数据初始化 //第一种情况 tableData: [{ id: 1, name: ["A", "B"] },{ id: 2, name: ["A", "C"] },{ id: 3, name: ["B", "C"] },{ …

配置阿里云CLI-aliyun命令与安装ossutil

1.aliyun命令官网文档 可以参考文档配置不同账户凭证 https://help.aliyun.com/document_detail/121259.html?spma2c4g.121193.0.i1 使用阿里云 CLI可以参考 https://help.aliyun.com/document_detail/110289.html?spma2c4g.121259.0.0.5ad27f08HvO1dw1&#xff09;账号添加…