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 Mem
	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();
	for(int k=blockDim.x/2; k>0; k /= 2){ // power of 2 reduction loop
		if(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 2
	for(int k=block2/2; k>0; k >>= 1){     // power of 2 reduction loop
		if(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 here
	if(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 here
		s[id]             += s[id + 32]; __syncwarp(); // the syncwarps
		if(id < 16) s[id] += s[id + 16]; __syncwarp(); // are required
		if(id <  8) s[id] += s[id +  8]; __syncwarp(); // for devices of
		if(id <  4) s[id] += s[id +  4]; __syncwarp(); // CC = 7 and above
		if(id <  2) s[id] += s[id +  2]; __syncwarp(); // for CC < 7
		if(id <  1) s[id] += s[id +  1]; __syncwarp(); // they do nothing

		if(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 v
	for(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 level
	v += warp.shfl_down(v,4);  // | reduce here
	v += warp.shfl_down(v,2);  // |
	v += warp.shfl_down(v,1);  // | 
						  //  use atomicAdd here to sum over warps
	if(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 4
	auto g = cg::this_grid();
	auto b = cg::this_thread_block();
	auto a = cg::coalesced_threads(); // active threads in warp
	float4 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 new
	if(a.size() >  8) v += a.shfl_down(v,8);  // thread 
	if(a.size() >  4) v += a.shfl_down(v,4);  // divergence
	if(a.size() >  2) v += a.shfl_down(v,2);  // allowed
	if(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 here
	if(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 4
	auto g = cg::this_grid();
	auto b = cg::this_thread_block();
	auto w = cg::tiled_partition<32>(b); // whole warp
	auto a = cg::coalesced_threads();    // active threads in warp
	int 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 a
	float4 v4 ={0,0,0,0};
	int id = a.thread_rank();
	for(int k=part_start+id; k<part_end; k+=a.size()) // adjacent adds within
		v4 += reinterpret_cast<const float4 *>(data)[k]; //    the warp
	float v = v4.x + v4.y + v4.z + v4.w;
	a.sync();
	// now reduce over a
	// first deal with items held by ranks >= kstart
	int 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 reduction
	for(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 data
    std::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 device
    dx = x;
    cx::timer tim;
    
    // cpu time test
    double host_sum = 0.0;
    for (int k = 0; k < N; k++) {
        host_sum += x[k];
    }
    double t1 = tim.lap_ms();

    // gpu test reduce0
    double 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 host
    gpu_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 reduce1
    dx = 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 reduce2
    dx = 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 reduce3
    dx = 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 reduce4
    dx = 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 reduce5
    dx = 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 reduce6
    dx = 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 reduce7
    dx = 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_L1
    dx = 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 coal
    thrust::device_vector<float>  dy_even(blocks);  // only even elements are used
	thrust::device_vector<float>  dy_odd(blocks);   // only odd elements are used
    dx = 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 buffer
            reduce7_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 any
    dx = 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 reduce8
    dx = 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的数量、数据计算的总量等都有关系,实际应用中可能需要进一步微调。

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

JVM 分析GC日志

GC日志参数 -verbose:gc 输出gc日志信息&#xff0c;默认输出到标准输出 -XX:PrintGC 输出GC日志。类似&#xff1a;-verbose:gc -XX:PrintGCDetails 在发生垃圾回收时打印内存回收详细的日志&#xff0c;并在进程退出时输出当前内存各区域分配情况 -XX:PrintGCTimeStam…

【TiDB理论知识10】TiDB6.0新特性

新特性 Placement Rules in SQL 小表缓存 内存悲观锁 Top SQL TiDB Enterprise Manager 一 Placement Rules in SQL Placement Rules in SQL 之前会遇到的问题 比如 北京的业务需要访问 T2 和 T3表 &#xff0c;但是T3表的数据在纽约 纽约的业务需要问访T4 T5 T6表…

2023 金砖国家职业技能大赛网络安全省赛理论题样题(金砖国家未来技能挑战赛)

2023 金砖国家职业技能大赛网络安全省赛理论题样题&#xff08;金砖国家未来技能挑战赛&#xff09; 一、参加比赛的形式 团队参与&#xff0c;每队2名选手&#xff08;设队长1名&#xff09;。 二、项目项目阶段简介 项目由四个阶段组成&#xff0c;将按顺序完成。向参与者…

Notes数据直接在Excel中统计

大家好&#xff0c;才是真的好。 我希望你看过前面两篇内容《Domino REST API安装和运行》和《Domino REST API安装和运行》&#xff0c;因为今天我们正是使用REST API方式在Excel中查询和统计Notes数据。 不过首先你得知道一个OData协议&#xff0c;全名Open Data Protocol(…

Leetcode1038. 从二叉搜索树到更大和树

Every day a Leetcode 题目来源&#xff1a;1038. 从二叉搜索树到更大和树 解法1&#xff1a;中序遍历 观察示例 1&#xff0c;我们发现了规律&#xff1a; 二叉搜索树的中序遍历是一个单调递增的有序序列。 本题中要求我们将每个节点的值修改为原来的节点值加上所有大于它…

CSS——选择器、PxCook软件、盒子模型

1、选择器 1.1 结构伪类选择器 作用&#xff1a;根据元素的结构关系查找元素。 1.1.1 :nth-child&#xff08;公式&#xff09; 作用&#xff1a;根据元素的结构关系查找多个元素 <!DOCTYPE html> <html lang"en"> <head><meta charset"…

编程过程中出现bug如何应对?

编程过程中出现bug如何应对&#xff1f; 1.找错误原因 如果完全不知道出错的原因&#xff0c;或者说存在着很多错误的有原因&#xff0c;----》控制变量法 例如&#xff0c;昨天我在使用torchrun 多卡并行一个程序的时候&#xff0c;出现了大量的bug, 于是我将报错信息放在网…

Java动态代理实现与原理详细分析

Java动态代理实现与原理详细分析 关于Java中的动态代理&#xff0c;我们首先需要了解的是一种常用的设计模式–代理模式&#xff0c;而对于代理&#xff0c;根据创建代理类的 时间点&#xff0c;又可以分为静态代理和动态代理。 1、代理模式 代理模式是常用的java设计模式&…

kafka学习笔记--基础知识概述

本文内容来自尚硅谷B站公开教学视频&#xff0c;仅做个人总结、学习、复习使用&#xff0c;任何对此文章的引用&#xff0c;应当说明源出处为尚硅谷&#xff0c;不得用于商业用途。 如有侵权、联系速删 视频教程链接&#xff1a;【尚硅谷】Kafka3.x教程&#xff08;从入门到调优…

Kafka 的消息格式:了解消息结构与序列化

Kafka 作为一款高性能的消息中间件系统&#xff0c;其消息格式对于消息的生产、传输和消费起着至关重要的作用。本篇博客将深入讨论 Kafka 的消息格式&#xff0c;包括消息的结构、序列化与反序列化&#xff0c;以及一些常用的消息格式选项。通过更丰富的示例代码和深入的解析&…

【Quasar】暗黑主题随系统切换部分组件无法随系统切换

问题描述 Quasar部分组件无法随系统切换主题 。 假如系统、Quasar主题为白天模式。Quasar设置主题随系统切换&#xff0c;当系统切换暗黑模式时&#xff0c;Quasar导航栏无法正常切换为暗黑模式&#xff0c;此时背景还是白天模式&#xff0c;如图 正常切换参考图 正常暗黑…

【musl-pwn】msul-pwn 刷题记录 -- musl libc 1.2.2

前言 本文不分析 musl libc 相关源码&#xff0c;仅仅为刷题记录&#xff0c;请读者自行学习相关知识&#xff08;看看源码就行了&#xff0c;代码量也不大&#xff09; starCTF2022_babynote 保护&#xff1a;保护全开 程序与漏洞分析&#xff1a; 程序实现了一个菜单堆&…

第3章:知识表示:概述、符号知识表示、向量知识表示

&#x1f497;&#x1f497;&#x1f497;欢迎来到我的博客&#xff0c;你将找到有关如何使用技术解决问题的文章&#xff0c;也会找到某个技术的学习路线。无论你是何种职业&#xff0c;我都希望我的博客对你有所帮助。最后不要忘记订阅我的博客以获取最新文章&#xff0c;也欢…

Python 从入门到精通 学习笔记 Day01

Python 从入门到精通 第一天 今日目标 计算机组成原理、编程语言、Python环境安装 第一个Python程序、PyCharm的安装与使用 Python的基础语法、Python的基本数据类型 一、计算机组成原理 计算机的组成 计算机硬件通常由以下几个部分组成: 1.中央处理器(CPU):负责执行计算机…

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

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

Docker-多容器应用

一、概述 到目前为止&#xff0c;你一直在使用单个容器应用。但是&#xff0c;现在您将 MySQL 添加到 应用程序堆栈。经常会出现以下问题 - “MySQL将在哪里运行&#xff1f;将其安装在同一个 容器还是单独运行&#xff1f;一般来说&#xff0c;每个容器都应该做一件事&#x…

题目分析,高度理解一维二维数组的申请和[]是什么运算符

第0题: 动态申请二维数组并输出非负数和 和负数出现次数 思路:输入数组大小,然后申请内存并不对其初始化,提高速度,传入数据到申请的数组中,判断如果数组中有元素小于0对其进行计数,否则加上非0数最后输出答案,释放内存 第一题: 解答: 运行结果: 思路分析: 创建长度为20的…

聚观早报 |东方甄选将上架文旅产品;IBM首台模块化量子计算机

【聚观365】12月6日消息 东方甄选将上架文旅产品 IBM首台模块化量子计算机 新思科技携手三星上新兴领域 英伟达与软银推动人工智能研发 苹果对Vision Pro供应商做出调整 东方甄选将上架文旅产品 东方甄选宣布12月10日将在东方甄选APP上线文旅产品&#xff0c;受这一消息影…

【算法】算法题-20231207

这里写目录标题 一、共同路径二、数字列表排序三、给定两个整数 n 和 k&#xff0c;返回 1 … n 中所有可能的 k 个数的组合。 一、共同路径 给你一个完整文件名组成的列表&#xff0c;请编写一个函数&#xff0c;返回他们的共同目录路径。 # nums[/hogwarts/assets/style.cs…

1-Tornado的介绍

1 tornado的介绍 **Tornado**是一个用Python编写的可扩展的、无阻塞的**Web应用程序框架**和**Web服务器**。 它是由FriendFeed开发使用的&#xff1b;该公司于2009年被Facebook收购&#xff0c;而Tornado很快就开源了龙卷风以其高性能着称。它的设计允许处理大量并发连接&…