Skip to content

Conversation

junjihashimoto
Copy link
Collaborator

@junjihashimoto junjihashimoto commented Sep 5, 2025

The dev branch has compilation errors due to an incorrect INCLUDE header.
This PR adds the dev branch to CI and fixes the error.

@junjihashimoto junjihashimoto force-pushed the fix/dev-ci branch 2 times, most recently from a809765 to 9cfd436 Compare September 7, 2025 06:54
@junjihashimoto junjihashimoto force-pushed the fix/dev-ci branch 6 times, most recently from 6976369 to 2bc52bf Compare September 9, 2025 05:48
Comment on lines +845 to +848
Tensor tensor = createTensor(ctx, shape, ki8);
wgpuQueueWriteBuffer(ctx.queue, tensor.data.buffer, 0, packed.data(),
tensor.data.size);
return tensor;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ki8 is packed into uint32_t while the shape is the same.
It caused out of bounds access and segmentation faults when copying data.

Comment on lines +1617 to +1618
// cbData->buffer needs to be freed, but calling it here will cause a segmentation fault.
// wgpuBufferRelease(cbData->buffer);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the appropriate time to release it, but if we run it here, a segmentation fault will occur.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, hard to manage, got stuck on this some too across platforms. Maybe we can return a pointer to the buffer and require the frontend consumer to release it?

cmake/dawn.cmake Outdated
Comment on lines 112 to 119
if(APPLE)
set(ABSEIL_COPTS_FILE "${DAWN_DIR}/third_party/abseil-cpp/absl/copts/GENERATED_AbseilCopts.cmake")
if(EXISTS "${ABSEIL_COPTS_FILE}")
file(READ "${ABSEIL_COPTS_FILE}" COPTS_CONTENT)
string(REGEX REPLACE "-msse4\\.1" "" COPTS_CONTENT "${COPTS_CONTENT}")
file(WRITE "${ABSEIL_COPTS_FILE}" "${COPTS_CONTENT}")
endif()
endif()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many differences due to the line ending code being changed from DOS to Unix, but this is the only part that needs to be corrected. There is no msse4.1 flag on MacOS, so we need to remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm not familiar / rarely use the cmake builds. @MichealReed if you have a chance maybe could see if this these changes make sense (could be after we merge to dev).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@junjihashimoto maybe we can just merge the changes from https://github.com/Practicalxr/minigpu/blob/master/minigpu_ffi/src/cmake/dawn.cmake? This successfully builds Dawn for mobile platforms now too. I think the core of getting it to build on Mac/iOS was disabling glfw and tint test/cmd/examples.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MichealReed I tried using the dawn.cmake with gpu.cpp.

I get the following error:

gpu.cpp/external/dawn/src/dawn/native/metal/PhysicalDeviceMTL.mm:140:50: error: use of undeclared identifier 'kIOMainPortDefault'
  140 |         AcquireIORef(IOServiceGetMatchingService(kIOMainPortDefault, matchingDict.Detach()));

This is due to differences in OS versions. Setting kIOMainPortDefault to 0 allows you to proceed.

STDLIB := -stdlib=libc++
endif
FLAGS=-std=c++17 $(STDLIB) -I$(GPUCPP) -I$(GPUCPP)/third_party/headers -L$(GPUCPP)/third_party/lib run.cpp -ldl -lwebgpu_dawn
FLAGS=-std=c++17 $(STDLIB) -I$(GPUCPP) -I$(GPUCPP)/third_party/headers -I$(GPUCPP)/third_party/headers/webgpu -L$(GPUCPP)/third_party/lib run.cpp -ldl -lwebgpu_dawn -Wl,-rpath,$(GPUCPP)/third_party/lib
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a search path to the program so that we don't need to set LD_LIBRARY_PATH.

@junjihashimoto junjihashimoto marked this pull request as ready for review September 11, 2025 17:09
for (int i = 0; i < N; ++i) {
inputArr[i] = static_cast<float>(i) / 10.0; // dummy input data
}
std::cout << Shape{N} << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit, but generally try to avoid iostream (mostly use cstdio)

gpu.hpp Outdated
}
};

inline std::ostream& operator<<(std::ostream& os, const Shape& shape)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same as above re avoiding iostream)

@austinvhuang
Copy link
Contributor

Thanks very much. Any objections to removing the iostream bits? Besides that, can go ahead and merge to dev.

Would be helpful if @MichealReed or others using the cmake builds could chime in on the cmake implementation as I'm not that familiar with the implementation / usage.

@junjihashimoto
Copy link
Collaborator Author

@austinvhuang
Thank you for your review. I don't need iostreams, but some kind of stringification function would make printf debugging easier.
There's also std::format, but it might be too early to use it. (I just noticed it while researching.)
https://www.cppstories.com/2022/custom-stdformat-cpp20/
A simple 'templatestd::string to_string(const T& u)' would be sufficient.

@austinvhuang austinvhuang merged commit 22692e2 into AnswerDotAI:dev Oct 8, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants