// OpenCL卷积核
__kernel void convolution(__global const float *restrict inputImage,
__global float *restrict outputImage,
__constant const float *restrict filter,
const int filterWidth)
{
// 計算濾波器寬度的一半
int half_filter_width = filterWidth >> 1;
// 獲取圖像的寬度和高度
int imageWidth = get_global_size(0);
int imageHeight = get_global_size(1);
// 獲取當前工作項在 x 和 y 方向上的全局坐標
int x = get_global_id(0);
int y = get_global_id(1);
// 計算卷積的邊界
int row_offset_min = -clamp(y, 0, half_filter_width);
int row_offset_max = clamp(half_filter_width, imageHeight - 1 - y, half_filter_width);
int col_offset_min = -clamp(x, 0, half_filter_width);
int col_offset_max = clamp(half_filter_width, imageWidth - 1 - x, half_filter_width);
// 初始化卷積的總和
float sum = 0;
// 循環遍歷卷積的每個元素
for (int row_offset = row_offset_min; row_offset <= row_offset_max; row_offset++) {
int imageRow = y + row_offset;
int filterRow = half_filter_width + row_offset;
int imageBase = imageRow * imageWidth + x;
int filterBase = filterRow * filterWidth + half_filter_width;
int filterOffset = col_offset_min;
do {
// 獲取當前濾波器和圖像像素的值
float filterValue = filter[filterBase + filterOffset];
// 判斷濾波器值是否非零,若是則累加到總和中
if (filterValue != 0) {
sum = mad(filterValue, inputImage[imageBase + filterOffset], sum);
}
} while (++filterOffset <= col_offset_max); // 迭代直到達到列的邊界
}
// 將卷積的結果寫入輸出圖像
outputImage[y * imageWidth + x] = sum;
}
VECTOR_WIDTH = 2
Nov 11, 2023contributed by < haoyu0970624763 > 測驗 1 跨平台的 ASR (arithmetic right shift) 實作 #include <stdio.h> int asr_i(signed int m, unsigned int n) { const int logical = (((int) -1) >> 1) > 0; unsigned int fixu = -(logical & (m < 0));
Mar 30, 2023Emotion Recognition for Cognitive Edge Computing Using Deep Learning 當資料從 sensor / IoT 大量傳輸到處理中心時 , 主要有三個挑戰 : latency, scalability, and security latency : 將 vedio data 輸入從 sensor 送到 cloud , 在 cloud 推斷結果 , 再 return 結果 , 這樣會造成許多延遲 , 此時 data scaliing 是一個有效運用資源的方法 邊緣運算 : 從 sensor / IoT 傳遞資料上去處中心時時需要大量的頻寬以及足夠的時間 , 因此 , 在連續的資料傳輸中 , 資料應該被預處理以減輕傳遞的負擔 , 可以为用户提供更少的延迟和实时体验 Edge devices : 1 個 edge server , 一個行動通信基地台 , 數個 end devices(數據來源) edge server 位置處於 sensor / IoT gateways 附近可以減低 latency
Feb 15, 2023什麼是機器學習 機器學習就是讓機器能自動找到一個function 主要分成幾大類 回歸(Regression) 輸出是一個連續的數值,比如PM2.5數值預測。 分類(Classification) 輸出是一個離散的值。
Nov 6, 2022or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up