Commit 0ab06415 authored by root's avatar root
Browse files

update hipcc-thrust resize example

parent 7fb5cae5
file(REMOVE_RECURSE
"CMakeFiles/resize-test.dir/resize-test.cpp.o"
"resize-test"
"resize-test.pdb"
)
# Per-language clean rules from dependency scanning.
foreach(lang CXX)
include(CMakeFiles/resize-test.dir/cmake_clean_${lang}.cmake OPTIONAL)
endforeach()
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.16
CMakeFiles/resize-test.dir/resize-test.cpp.o
/workspace/sunzhq/tmp/hipcc-thrust/resize-test.cpp
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.16
CMakeFiles/resize-test.dir/resize-test.cpp.o: ../resize-test.cpp
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.16
# compile CXX with /opt/dtk-25.04.3/bin/hipcc
CXX_FLAGS = -g --rocm-path=/opt/dtk-25.04.3 --offload-arch=gfx936 -g -O1 -std=gnu++17
CXX_DEFINES = -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_HIP -DTHRUST_HOST_SYSTEM=THRUST_HOST_SYSTEM_CPP -D__HIP_PLATFORM_AMD__=1
CXX_INCLUDES =
/opt/dtk-25.04.3/bin/hipcc -g CMakeFiles/resize-test.dir/resize-test.cpp.o -o resize-test
CMAKE_PROGRESS_1 = 1
CMAKE_PROGRESS_2 = 2
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.16
# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target
# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =
.SUFFIXES: .hpux_make_needs_suffix_list
# Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake
# The command to remove a file.
RM = /usr/bin/cmake -E remove -f
# Escaping for special characters.
EQUALS = =
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /workspace/sunzhq/tmp/hipcc-thrust
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /workspace/sunzhq/tmp/hipcc-thrust/build
#=============================================================================
# Targets provided globally by CMake.
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
/usr/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache
# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
# The main all target
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /workspace/sunzhq/tmp/hipcc-thrust/build/CMakeFiles /workspace/sunzhq/tmp/hipcc-thrust/build/CMakeFiles/progress.marks
$(MAKE) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start /workspace/sunzhq/tmp/hipcc-thrust/build/CMakeFiles 0
.PHONY : all
# The main clean target
clean:
$(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean
# The main clean target
clean/fast: clean
.PHONY : clean/fast
# Prepare targets for installation.
preinstall: all
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall
# Prepare targets for installation.
preinstall/fast:
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast
# clear depends
depend:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend
#=============================================================================
# Target rules for targets named resize-test
# Build rule for target.
resize-test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 resize-test
.PHONY : resize-test
# fast build rule for target.
resize-test/fast:
$(MAKE) -f CMakeFiles/resize-test.dir/build.make CMakeFiles/resize-test.dir/build
.PHONY : resize-test/fast
resize-test.o: resize-test.cpp.o
.PHONY : resize-test.o
# target to build an object file
resize-test.cpp.o:
$(MAKE) -f CMakeFiles/resize-test.dir/build.make CMakeFiles/resize-test.dir/resize-test.cpp.o
.PHONY : resize-test.cpp.o
resize-test.i: resize-test.cpp.i
.PHONY : resize-test.i
# target to preprocess a source file
resize-test.cpp.i:
$(MAKE) -f CMakeFiles/resize-test.dir/build.make CMakeFiles/resize-test.dir/resize-test.cpp.i
.PHONY : resize-test.cpp.i
resize-test.s: resize-test.cpp.s
.PHONY : resize-test.s
# target to generate assembly for a file
resize-test.cpp.s:
$(MAKE) -f CMakeFiles/resize-test.dir/build.make CMakeFiles/resize-test.dir/resize-test.cpp.s
.PHONY : resize-test.cpp.s
# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... rebuild_cache"
@echo "... resize-test"
@echo "... edit_cache"
@echo "... resize-test.o"
@echo "... resize-test.i"
@echo "... resize-test.s"
.PHONY : help
#=============================================================================
# Special targets to cleanup operation of make.
# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system
# Install script for directory: /workspace/sunzhq/tmp/hipcc-thrust
# Set the install prefix
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "/usr/local")
endif()
string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
# Set the install configuration name.
if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
if(BUILD_TYPE)
string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
else()
set(CMAKE_INSTALL_CONFIG_NAME "Debug")
endif()
message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
endif()
# Set the component getting installed.
if(NOT CMAKE_INSTALL_COMPONENT)
if(COMPONENT)
message(STATUS "Install component: \"${COMPONENT}\"")
set(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
else()
set(CMAKE_INSTALL_COMPONENT)
endif()
endif()
# Install shared libraries without execute permission?
if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
set(CMAKE_INSTALL_SO_NO_EXE "0")
endif()
# Is this installation the result of a crosscompile?
if(NOT DEFINED CMAKE_CROSSCOMPILING)
set(CMAKE_CROSSCOMPILING "FALSE")
endif()
if(CMAKE_INSTALL_COMPONENT)
set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt")
else()
set(CMAKE_INSTALL_MANIFEST "install_manifest.txt")
endif()
string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT
"${CMAKE_INSTALL_MANIFEST_FILES}")
file(WRITE "/workspace/sunzhq/tmp/hipcc-thrust/build/${CMAKE_INSTALL_MANIFEST}"
"${CMAKE_INSTALL_MANIFEST_CONTENT}")
File added
// hip_resize_device_vector.cpp
#include <hip/hip_runtime.h>
#include <thrust/device_vector.h>
#include <cstdint>
#include <iostream>
#include <thrust/host_vector.h>
int main() {
const size_t size_in_bytes = 200 * 1024; // 200 KB
try {
// 创建一个空的 device_vector
thrust::device_vector<uint8_t> d_vec;
// 分配 200 KB 内存(即 200 * 1024 个 uint8_t 元素)
d_vec.resize(size_in_bytes);
std::cout << "Successfully allocated " << size_in_bytes << " bytes on GPU." << std::endl;
std::cout << "Device vector size: " << d_vec.size() << " elements." << std::endl;
// // 将 GPU 数据复制到 CPU
// thrust::device_vector<uint8_t> d_vec(100,1);
// thrust::host_vector<uint8_t> h_vec = d_vec;
// // 打印前 10 个字节和最后 1 个字节
// std::cout << "First 10 bytes: ";
// for (size_t i = 0; i < 10 && i < h_vec.size(); ++i) {
// std::cout << static_cast<int>(h_vec[i]) << " ";
// }
// std::cout << "\nLast byte: " << static_cast<int>(h_vec.back()) << std::endl;
uint8_t* raw_ptr = thrust::raw_pointer_cast(d_vec.data());
if (raw_ptr != nullptr) {
// std::cout << "GPU memory allocated successfully at: " << raw_ptr << std::endl;
std::cout << "GPU memory allocated at address: 0x"
<< std::hex << reinterpret_cast<uintptr_t>(raw_ptr) << std::dec << std::endl;
} else {
std::cerr << "Failed to allocate GPU memory!" << std::endl;
return -1;
}
// 可选:验证分配是否成功(例如通过访问第一个和最后一个元素)
if (!d_vec.empty()) {
d_vec[0] = 42;
d_vec.back() = 24;
std::cout << "Test write successful." << std::endl;
}
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return -1;
}
return 0;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment