Skip to content

Commit 33ab78c

Browse files
committed
Fixed the examples of module2
1 parent 8838a78 commit 33ab78c

5 files changed

Lines changed: 31 additions & 31 deletions

File tree

modules/module2/examples/01_shared_memory_transpose_hip.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,13 @@ int main() {
356356
free(h_output_shared);
357357
free(h_output_optimized);
358358
free(h_output_cpu);
359-
hipFree(d_input);
360-
hipFree(d_output_naive);
361-
hipFree(d_output_shared);
362-
hipFree(d_output_optimized);
363-
hipFree(d_bank_data);
364-
hipEventDestroy(start);
365-
hipEventDestroy(stop);
359+
HIP_CHECK(hipFree(d_input));
360+
HIP_CHECK(hipFree(d_output_naive));
361+
HIP_CHECK(hipFree(d_output_shared));
362+
HIP_CHECK(hipFree(d_output_optimized));
363+
HIP_CHECK(hipFree(d_bank_data));
364+
HIP_CHECK(hipEventDestroy(start));
365+
HIP_CHECK(hipEventDestroy(stop));
366366

367367
printf("\nHIP shared memory transpose example completed successfully!\n");
368368
return 0;

modules/module2/examples/02_memory_coalescing_hip.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ class MemoryBenchmark {
184184
}
185185

186186
~MemoryBenchmark() {
187-
hipFree(d_data);
188-
hipEventDestroy(start);
189-
hipEventDestroy(stop);
187+
HIP_CHECK(hipFree(d_data));
188+
HIP_CHECK(hipEventDestroy(start));
189+
HIP_CHECK(hipEventDestroy(stop));
190190
}
191191

192192
float testCoalesced(int blocks, int threads) {
@@ -382,10 +382,10 @@ void runParticleBenchmarks() {
382382
#endif
383383

384384
// Cleanup
385-
hipFree(soa.x); hipFree(soa.y); hipFree(soa.z);
386-
hipFree(soa.vx); hipFree(soa.vy); hipFree(soa.vz);
387-
hipFree(soa.mass); hipFree(aos);
388-
hipEventDestroy(start); hipEventDestroy(stop);
385+
HIP_CHECK(hipFree(soa.x)); HIP_CHECK(hipFree(soa.y)); HIP_CHECK(hipFree(soa.z));
386+
HIP_CHECK(hipFree(soa.vx)); HIP_CHECK(hipFree(soa.vy)); HIP_CHECK(hipFree(soa.vz));
387+
HIP_CHECK(hipFree(soa.mass)); HIP_CHECK(hipFree(aos));
388+
HIP_CHECK(hipEventDestroy(start)); HIP_CHECK(hipEventDestroy(stop));
389389
}
390390

391391
void runVectorizationBenchmark() {
@@ -439,10 +439,10 @@ void runVectorizationBenchmark() {
439439
printf("Vector bandwidth: %.2f GB/s\n",
440440
(bytes_transferred / (1024.0 * 1024.0 * 1024.0)) / (vector_time / 1000.0));
441441

442-
hipFree(d_float_data);
443-
hipFree(d_float4_data);
444-
hipEventDestroy(start);
445-
hipEventDestroy(stop);
442+
HIP_CHECK(hipFree(d_float_data));
443+
HIP_CHECK(hipFree(d_float4_data));
444+
HIP_CHECK(hipEventDestroy(start));
445+
HIP_CHECK(hipEventDestroy(stop));
446446
}
447447

448448
int main() {

modules/module2/examples/03_texture_memory_hip.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ __global__ void textureFilterKernel(hipTextureObject_t texObj, float *output,
2121
float v = (float)(y + fy + 0.5f) / height;
2222

2323
// Texture automatically handles boundary conditions and interpolation
24-
float value = tex2D<float>(texObj, u, v);
24+
float value = hipTex2D<float>(texObj, u, v);
2525
sum += value;
2626
}
2727
}
@@ -42,7 +42,7 @@ __global__ void textureTranspose(hipTextureObject_t texObj, float *output,
4242
float v = (y + 0.5f) / height;
4343

4444
// Fetch using texture cache
45-
float value = tex2D<float>(texObj, u, v);
45+
float value = hipTex2D<float>(texObj, u, v);
4646

4747
// Write transposed
4848
if (y < width && x < height) {
@@ -71,7 +71,7 @@ __global__ void bilinearInterpolation(hipTextureObject_t texObj, float *output,
7171
float v = src_y / in_height;
7272

7373
// Hardware bilinear interpolation
74-
float interpolated = tex2D<float>(texObj, u, v);
74+
float interpolated = hipTex2D<float>(texObj, u, v);
7575

7676
output[y * out_width + x] = interpolated;
7777
}
@@ -134,7 +134,7 @@ __global__ void amdOptimizedTextureAccess(hipTextureObject_t texObj, float *outp
134134
float u = (x + 0.5f) / width;
135135
float v = (y + 0.5f) / height;
136136

137-
float value = tex2D<float>(texObj, u, v);
137+
float value = hipTex2D<float>(texObj, u, v);
138138
output[pixel_id] = value;
139139
}
140140
}
@@ -293,10 +293,10 @@ void demonstrateTextureMemory() {
293293
HIP_CHECK(hipEventDestroy(start));
294294
HIP_CHECK(hipEventDestroy(stop));
295295

296-
hipFree(d_input);
297-
hipFree(d_output_texture);
298-
hipFree(d_output_manual);
299-
hipFree(d_resized);
296+
HIP_CHECK(hipFree(d_input));
297+
HIP_CHECK(hipFree(d_output_texture));
298+
HIP_CHECK(hipFree(d_output_manual));
299+
HIP_CHECK(hipFree(d_resized));
300300

301301
free(h_input);
302302
free(h_output_texture);

modules/module2/examples/04_unified_memory_hip.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class UnifiedMemoryDemo {
9393
}
9494

9595
~UnifiedMemoryDemo() {
96-
hipFree(data);
96+
HIP_CHECK(hipFree(data));
9797
}
9898

9999
void processOnGPU() {
@@ -257,7 +257,7 @@ void performanceComparison() {
257257

258258
// Cleanup
259259
free(h_data);
260-
hipFree(d_data);
260+
HIP_CHECK(hipFree(d_data));
261261
}
262262

263263
// Memory usage analysis

modules/module2/examples/05_memory_bandwidth_optimization_hip.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ class BandwidthTester {
235235
}
236236

237237
~BandwidthTester() {
238-
hipFree(d_input);
239-
hipFree(d_output);
238+
HIP_CHECK(hipFree(d_input));
239+
HIP_CHECK(hipFree(d_output));
240240
}
241241

242242
double testBandwidth(const char* test_name, void (*kernel)(float*, float*, size_t),
@@ -388,7 +388,7 @@ void analyzeAccessPatterns() {
388388
HIP_CHECK(hipEventDestroy(stop));
389389
}
390390

391-
hipFree(d_temp);
391+
HIP_CHECK(hipFree(d_temp));
392392
}
393393

394394
void demonstrateBandwidthOptimization() {

0 commit comments

Comments
 (0)